Learn R Programming

zephyr (version 0.1.2)

msg: Write messages based on verbosity level

Description

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.

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())

Value

Return from msg_fun()

Arguments

message

character string with the text to display.

levels_to_write

character vector with the verbosity levels for which the message should be displayed. Options are minimal, verbose, and debug.

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 environment to use for evaluating the verbosity level. Default parent.frame() will be sufficient for most use cases. Parsed on to msg_fun().

Examples

Run this code
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