The msg() function is a general utility function for writing messages to
the console based on the verbosity_level set for your session and package.
For simple messages in your functions the recommended approach is to use the following wrappers for consistency across packages:
msg_success(): To indicate a successful operation. Wrapper aroundmsg()usingcli::cli_alert_success()to display the message.msg_danger(): To indicate a failed operation. Wrapper aroundmsg()usingcli::cli_alert_danger()to display the message.msg_warning(): To indicate a warning. Wrapper aroundmsg_verbose()usingcli::cli_alert_warning()to display the message.msg_info(): To provide additional information. Wrapper aroundmsg_verbose()usingcli::cli_alert_info()to display the message.
For more control of how the messages are displayed use:
msg(): To write messages using custommsg_funfunctions and define your own verbosity levels to write.msg_verbose(): To write verbose messages with a custommsg_fun.msg_debug(): To to report messages only relevant when debugging.
For more information on the verbosity levels, see verbosity_level.
Usage
msg(
message,
levels_to_write = c("minimal", "verbose", "debug"),
msg_fun = cli::cli_alert,
...,
.envir = parent.frame()
)
msg_verbose(message, msg_fun = cli::cli_alert, ..., .envir = parent.frame())
msg_debug(message, msg_fun = cli::cli_alert, ..., .envir = parent.frame())
msg_success(message, ..., .envir = parent.frame())
msg_danger(message, ..., .envir = parent.frame())
msg_warning(message, ..., .envir = parent.frame())
msg_info(message, ..., .envir = parent.frame())Arguments
- message
characterstring with the text to display.- levels_to_write
charactervector with the verbosity levels for which the message should be displayed. Options areminimal,verbose, anddebug.- msg_fun
The function to use for writing the message. Most commonly from the cli package. Default is
cli::cli_alert().- ...
Additional arguments to pass to
msg_fun()- .envir
The
environmentto use for evaluating the verbosity level. Defaultparent.frame()will be sufficient for most use cases. Parsed on tomsg_fun().
