cellwise: The cellwise logger.

cellwiseR Documentation

The cellwise logger.

Description

The cellwise logger registers the row, column, old, and new value of cells that changed, along with a step number, timestamp, source reference, and the expression used to alter a dataset.

Usage

cellwise(key, verbose=TRUE, tempfile=file.path(tempdir(),"cellwise.csv"))

Arguments

key

[character|integer] index to column that uniquely identifies a row.

verbose

[logical] toggle verbosity.

tempfile

[character] filename for temporary log storage.

Format

An R6 class object.

Creating a logger

cellwise$new(key, verbose=TRUE, file=tempfile())

key [character|integer] index to column that uniquely identifies a row.
verbose [logical] toggle verbosity.
tempfile [character] filename for temporary log storage.

Dump options

$dump(file=NULL)

file [character] location to write final output to.

The default location is "cellwise.csv" in an interactive session, and "DATA_cellwise.csv" in a script that executed via run_file. Here, DATA is the variable name of the data being tracked or the label provided with start_log.

Getting data from the logger

$logdata() Returns a data frame with the current log.

Details

At initialization, the cellwise logger opens a connection to a temporary file. All logging info is appended to that connection. When dump_log is called, the temporary file is closed, copied to the output file, and reopened for writing. The connection is closed automatically when the logger is destroyed, for example when calling stop_log().

See Also

Other loggers: expression_logger, filedump, no_log, simple

Examples

logfile <- tempfile(fileext=".csv")

# convert height from inch to cm and log changes.
# we need to set a unique key.
women$sleutel <- 1:nrow(women)
out <- women %L>%
  start_log(log=cellwise$new(key="sleutel")) %L>%
  {.$height <- .$height*2.54; .} %L>%
  dump_log(file=logfile, stop=TRUE)

read.csv(logfile) %L>% head()

# work with an externally defined logger.
iris$id <- seq_len(nrow(iris))
logger <- cellwise$new(key="id")
iris %L>% 
  start_log(logger) %L>%
  head() %L>%
  stop_log(dump=FALSE)
logger$logdata()



lumberjack documentation built on March 31, 2023, 7:56 p.m.