| err | R Documentation |
These functions are similar to stop()/cli::cli_abort(), warning()/cli::cli_warn(), and message()/cli::cli_inform(), throwing an error, warning, and message, respectively. Minor processing is done to capitalize the first letter of the message, add a period at the end (if it makes sense to), and add information about the calling function.
err(m, .call, .envir = rlang::caller_env())
wrn(m, immediate = TRUE, .envir = rlang::caller_env())
msg(m, .envir = rlang::caller_env())
m |
the message to be displayed, passed to the |
.call |
the execution environment of a currently running function, e.g. |
.envir |
the environment to evaluate the glue expressions in. See |
immediate |
whether to output the warning immediately ( |
These functions are simple wrappers for the corresponding functions in rlang, namely rlang::abort() for err(), rlang::warn() for wrn(), and rlang::inform() for msg(), but which function almost identically to the cli versions. Their main differences are that they additionally process the input (capitalizing the first character of the message and adding a period to the end if needed, unless multiple strings are provided). err() is used inside all arg_*() functions in arg.
err() throws an error condition. wrn() throws a warning condition and invisibly returns the formatted warning message as a string. msg() signals a message and invisibly returns NULL.
Base versions: stop(), warning(), message()
rlang versions: rlang::abort(), rlang::warn(), rlang::inform()
cli versions: cli::cli_abort(), cli::cli_warn(), cli::cli_inform()
f <- function(x) {
err("this is an error, and {.arg x} is {.type {x}}")
}
try(f(1))
g <- function(x) {
wrn("this warning displayed last", immediate = FALSE)
wrn("this warning displayed first")
}
try(g(1))
h <- function() {
msg("is a period added at the end?")
msg("not when the message ends in punctuation!")
msg(c("or when multiple",
"!" = "messages",
"v" = "are",
"*" = "displayed"))
msg("otherwise yes")
}
h()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.