caller_arg {rlang} | R Documentation |
Find the caller argument for error messages
Description
caller_arg()
is a variant of substitute()
or ensym()
for
arguments that reference other arguments. Unlike substitute()
which returns an expression, caller_arg()
formats the expression
as a single line string which can be included in error messages.
When included in an error message, the resulting label should generally be formatted as argument, for instance using the
.arg
in the cli package.Use
@inheritParams rlang::args_error_context
to document anarg
orerror_arg
argument that takeserror_arg()
as default.
Arguments
arg |
An argument name in the current function. |
Examples
arg_checker <- function(x, arg = caller_arg(x), call = caller_env()) {
cli::cli_abort("{.arg {arg}} must be a thingy.", arg = arg, call = call)
}
my_function <- function(my_arg) {
arg_checker(my_arg)
}
try(my_function(NULL))
[Package rlang version 1.1.4 Index]