Check scalar arg in x
check_scalar_arg_in_x.RdCheck if scalar arg %in% x.
Arguments
- arg
(object)
The argument to check.- x
(Atomic vector)
Scalarargmust match one value inx.- 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_scalar_arg_in_x() examples
#----------------------------------------------------------------------------
library(bkcheck)
f <- function(x) {
chr <- c("a", "b", "c")
x |>
check_scalar_arg_in_x(chr)
}
f("a")
try(f("d"))
#> Error : Argument `x` is 'd' but must be exactly one of:
#> 'a', 'b', or 'c'
#>
#> Call: f(x = "d")