cat_*() functions control user output in patter functions with the .verbose argument.
Arguments
- .fun
A
characterstring that defines the name of the parent function.- .verbose
A
logicalvariable or astringthat defines the path to a text file..verbose = FALSEsuppresses user outputs;.verbose = TRUEsends user outputs to the console;.verbose = file.path("path", "to", "text", "file.txt")sends user outputs to a.txtfile;
Details
These are internal functions.
cat_setup()sets up messages within functions;cat_init()defines acat()wrapper based on.verbose;cat_log_file()validates.verboseand, if necessary, creates the.txtfile;
Examples
if (FALSE) { # \dontrun{
# Define example function
wrap <- function(.verbose = getOption("Patter.verbose")) {
# Set up messages and exit handler
cats <- cat_setup(.fun = "wrap", .verbose = .verbose)
on.exit(eval(cats$exit, envir = cats$envir), add = TRUE)
# Run function
cats$cat("Running function...")
Sys.sleep(1)
}
# `.verbose = TRUE` sends user output to the console
wrap(.verbose = TRUE)
# `.verbose = {log}.txt` sends user output to file
log.txt <- tempfile(fileext = ".txt")
wrap(.verbose = log.txt)
readLines(log.txt)
unlink(log.txt)
# `.verbose = TRUE` suppresses user output
wrap(.verbose = FALSE)
} # }
