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 around msg()
using cli::cli_alert_success() to display the message.
msg_danger(): To indicate a failed operation. Wrapper around msg()
using cli::cli_alert_danger() to display the message.
msg_warning(): To indicate a warning. Wrapper around msg_verbose()
using cli::cli_alert_warning() to display the message.
msg_info(): To provide additional information. Wrapper around
msg_verbose() using cli::cli_alert_info() to display the message.
For more control of how the messages are displayed use:
msg(): To write messages using custom msg_fun functions and define your
own verbosity levels to write.
msg_verbose(): To write verbose messages with a custom msg_fun.
msg_debug(): To to report messages only relevant when debugging.
For more information on the verbosity levels, see verbosity_level.
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())
Return from msg_fun()
character string with the text to display.
character vector with the verbosity levels for
which the message should be displayed. Options are minimal, verbose, and
debug.
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()
The environment to use for evaluating the verbosity level.
Default parent.frame() will be sufficient for most use cases. Parsed on to
msg_fun().
msg("General message")
msg_success("Operation successful")
msg_danger("Operation failed")
msg_warning("Warning message")
msg_info("Additional information")
Run the code above in your browser using DataLab