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.

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.3 Index]