Check names
check_names_in_arg.RdCheck if arg has specified names.
Arguments
- arg
(object)
The argument to check.- names
(character)
The names that should matchnames(arg).- signal
(string:
c("error", "warning", "message"))
Must be one of"error","warning", or"message"."error"(default) callsbase::stop()to signal an error message."warning"callsbase::warning()to signal a warning message."message"callsbase::message()to signal a message.- msg
(string or
NULL:NULL)
A string that replaces the default message. Set asNULLto use the default message.- call.
(Scalar logical:
c(FALSE, TRUE))
Passed tostop()orwarning(). The defaultmsgincludes it's own formatted call, hencecall.should beFALSE(default). If you insert your ownmsg, then you may wantcall. = TRUE.
Examples
#----------------------------------------------------------------------------
# check_names_in_arg() examples
#----------------------------------------------------------------------------
library(bkcheck)
f <- function(x) {
x |>
check_names_in_arg(c("a", "b"))
}
f(c(a = 1, b = 2))
f(data.frame(a = 1, b = 2))
f(list(a = 1, b = 2))
try(f(1:2))
#> Error : Argument `x` must have all required names.
#>
#> Missing names: 'a', 'b'
#> Required names: 'a', 'b'
#>
#> Call: f(x = 1:2)
try(f(c(a = 1, 2)))
#> Error : Argument `x` must have all required names.
#>
#> Missing names: 'b'
#> Required names: 'a', 'b'
#>
#> Call: f(x = c(a = 1, 2))
try(f(list(a = 1, 2)))
#> Error : Argument `x` must have all required names.
#>
#> Missing names: 'b'
#> Required names: 'a', 'b'
#>
#> Call: f(x = list(a = 1, 2))