Checks whether an argument with no default value was supplied. An error will be thrown if rlang::is_missing(x) is TRUE, i.e., if an argument with no default is omitted from a function call.
Usage
arg_supplied(x, .arg = rlang::caller_arg(x), .msg = NULL, .call)Arguments
- x
the argument to be checked
- .arg
the name of the argument supplied to
xto appear in error messages. The default is to extract the argument's name usingrlang::caller_arg(). Ignored if.msgis supplied.- .msg
an optional alternative message to display if an error is thrown instead of the default message.
- .call
the execution environment of a currently running function, e.g.
.call = rlang::current_env(). The corresponding function call is retrieved and mentioned in error messages as the source of the error. Passed toerr(). Set toNULLto omit call information. The default is to search along the call stack for the first user-facing function in another package, if any.
Examples
f <- function(z) {
arg_supplied(z)
}
try(f(1)) ## No error: argument supplied
try(f()) ## Error!
#> Error : An argument to `z` must be supplied.
# Will not throw for NULL or default arguments
try(f(NULL)) ## No error: argument supplied
f2 <- function(z = NULL) {
arg_supplied(z)
}
try(f2()) ## No error; default provided