Skip to content

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 an arg or error_arg argument that takes error_arg() as default.



An argument name in the current function.


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

#> Error in my_function(NULL) : `my_arg` must be a thingy.