Generates a fairly flexible container to log stuff.

log_init(what, init.size, at = NULL, to = NULL)

Arguments

what

[named(character)]
Named character vector. The names (i.e., names(what)) describe which elements we want to log and the actual values represent the types/modes these values are stored as. Possible values are “integer”, “numeric”, “character”, “logical” for the respective scalar atomic values, or “list” for any other complex R objects, e.g., matrices, lists etc. Note that internally c("iter" = "numeric") is attached automatically and iter must be passed to log_update in subsequent calls.

init.size

[integer(1)]
Initial size of the log.

at

[integer]
Optional integer vector of times when logging should take place. If the iteration counter is in at, the state is logged, otherwise it is not.

to

[character(1)]
File path to log-directory. If not NULL, each call to log_update stores the serialized state in file “<to>/<iteration>.rds”.

Value

Logger environment.

See also

log_update

Examples

log = log_init(c("P" = "list", "f" = "list", "C" = "character"), init.size = 5L, at = c(1, 3)) # Note that div is not subject to logging since it was not specified in log_init log_update(log, P = matrix(runif(10), ncol = 2L), C = "a", f = runif(10), iter = 1, div = letters[1:3]) log_update(log, P = matrix(runif(10), ncol = 2L), C = "b", f = runif(10), iter = 2, div = letters[1:3]) log_update(log, P = matrix(runif(10), ncol = 2L), C = "a", f = runif(10), iter = 3, div = letters[1:3]) print(log$df)
#> iter P f C #> 1 1 0.600760.... 0.034241.... a #> 2 3 0.641679.... 0.174675.... a #> 3 0 #> 4 0 #> 5 0