cat_*()
functions control user output in patter
functions with the .verbose
argument.
Arguments
- .fun
A
character
string that defines the name of the parent function.- .verbose
A
logical
variable or astring
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;
Details
These are internal functions.
cat_setup()
sets up messages within functions;cat_init()
defines acat()
wrapper based on.verbose
;cat_log_file()
validates.verbose
and, if necessary, creates the.txt
file;
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)
} # }