Use rlang to set cli.default_handler to suppressMessages as a local or permanent option
Source:R/cli_quiet.R
cli_quiet.Rdcli_quiet() is a helper to enable a quiet option in other functions.
Usage
cli_quiet(quiet = FALSE, push = FALSE, .frame = rlang::caller_env())Arguments
- quiet
If
FALSE, leave cli.default_handler option unchanged. IfTRUE, set cli.default_handler tosuppressMessagestemporaily withrlang::local_options()or permanently withrlang::push_options().- push
If
TRUE, set cli.default_handler option withrlang::push_options().- .frame
The environment of a stack frame which defines the scope of the temporary options. When the frame returns, the options are set back to their original values.
Examples
test_fn <- function(quiet = FALSE) {
cli_quiet(quiet = quiet)
cli::cli_alert_info(
"{.arg quiet} is {.val {quiet}}"
)
}
options("cli.default_handler" = NULL)
test_fn()
#> ℹ `quiet` is FALSE
test_fn(quiet = TRUE)