Skip to contents

This function outputs (sinks) the console to a text file on disk.

Usage

logtext(
  expr,
  logger = get_logger(add_git_info = FALSE, init_log_file = FALSE),
  silent = FALSE,
  return_logger = FALSE
)

Arguments

expr

R expression(s) to output to text file

logger

logger object from get_logger() (default will create a new logger)

silent

(logical) whether to print file path to console after logging (default TRUE)

return_logger

(logical) whether to return the logger object (useful if no initial logger object was passed)

Value

Sinks output to text file, and returns logger object if requested

Details

This function uses base::sink() to output the console to a text file. The directory gentleman_logs/ will be created in the logger's directory if it doesn't already exist.

If the expressions in expr fail, console output will continue to be written to the log until sink() is manually executed.

Examples

if (FALSE) {
logtext(print("Hello world!"))

logger <- get_logger()
logger |> logtext(expr={
  print("model without covariates:")
  lm(y1 ~ x1, df) |> summary() |> print()
  print("model with covariates")
  lm(y1 ~ x1 + x2 + x3, df) |> summary() |> print()
})
}