cat_*()
functions control user output in patter
functions with the .verbose
argument.
cat_setup(.fun, .verbose)
cat_init(.verbose)
cat_log_file(.verbose)
A character
string that defines the name of the parent function.
A logical
variable or a string
that defines the path to a text file.
.verbose = FALSE
suppresses user outputs;
.verbose = TRUE
sends user outputs to the console;
.verbose = file.path("path", "to", "text", "file.txt")
sends user outputs to a .txt
file;
These are internal functions.
cat_setup()
sets up messages within functions;
cat_init()
defines a cat()
wrapper based on .verbose
;
cat_log_file()
validates .verbose
and, if necessary, creates the .txt
file;
if (FALSE) {
# 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)
}