Generates a fairly flexible container to log stuff.

init_logger(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 |link{update_logger} 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 update_logger stores the serialized state in file “<to>/<iteration>.rds”.

Value

[enviroment] Logger environment.

See also

update_logger

Examples

log = init_logger(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 init_logger update_logger(log, P = matrix(runif(10), ncol = 2L), C = "a", f = runif(10), iter = 1, div = letters[1:3]) update_logger(log, P = matrix(runif(10), ncol = 2L), C = "b", f = runif(10), iter = 2, div = letters[1:3]) update_logger(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.080750.... 0.874600.... a #> 2 3 0.680162.... 0.461186.... a #> 3 0 #> 4 0 #> 5 0