cellwise | R Documentation |
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.
cellwise(key, verbose=TRUE, tempfile=file.path(tempdir(),"cellwise.csv"))
key |
|
verbose |
|
tempfile |
|
An R6
class object.
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(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
.
$logdata()
Returns a data frame with the current log.
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()
.
Other loggers:
expression_logger
,
filedump
,
no_log
,
simple
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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.