An R6 logger that plugs into the lumberjack %L>% pipe and renders the same console output as %>=%: row/column counts, signed deltas, added/dropped column names, and approximate step timing.

Requires the R6 and lumberjack packages (both in Suggests). If either is missing, the class is unavailable but the rest of logrittr works normally.

Timing

lumberjack calls $add() after each step without providing a start time. Elapsed time is measured as the interval between two consecutive $add() calls. The first step always shows NA ms.

See also

Public fields

label

Set by lumberjack to the name of the tracked object.

Methods


Method new()

Create a new logrittr_logger.

Usage

logrittr_logger$new(verbose = TRUE, src_name = NULL)

Arguments

verbose

Logical. Whether to print log messages to the console. Default TRUE.

src_name

Character. Optional name of the source object, displayed as a header rule before the first step.


Method add()

Called by lumberjack after each pipe step.

Usage

logrittr_logger$add(meta, input, output)

Arguments

meta

List with elements expr and src (the step expression).

input

Data frame before the step.

output

Data frame after the step.


Method dump()

Called by dump_log(). Writes accumulated log to a CSV file. If verbose = TRUE, also prints the file path.

Usage

logrittr_logger$dump(file = NULL, ...)

Arguments

file

Character. Output file path. Defaults to "simple.csv" or "<label>_simple.csv" when a label is set.

...

Additional arguments passed to write.csv().


Method clone()

The objects of this class are cloneable with this method.

Usage

logrittr_logger$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

if (FALSE) { # \dontrun{
library(lumberjack)
library(dplyr)

iris %L>%
  start_log(log = logrittr_logger$new()) %L>%
  as_tibble() %L>%
  filter(Sepal.Length < 5) %L>%
  mutate(rn = row_number()) %L>%
  group_by(Species) %L>%
  summarise(n = n_distinct(rn)) %L>%
  dump_log(stop = TRUE)
  
  
logfile <- tempfile(fileext="r.log.csv")

iris %L>%
  start_log(log = logrittr_logger$new(verbose = FALSE, 
  label = "A reel simple example on iris df")) %L>%
  as_tibble()  %L>%
  filter(Sepal.Length < 5) %L>%
  mutate(rn = row_number()) %L>%
  group_by(Species) %L>%
  summarise(n = n_distinct(rn)) %L>%
  dump_log(file=logfile)

logdata <- read.csv(logfile)

head(logdata)

  
} # }