View source: R/util_expect_scalar.R
util_expect_scalar | R Documentation |
check, if a scalar/vector function argument matches expectations
util_expect_scalar(
arg_name,
allow_more_than_one = FALSE,
allow_null = FALSE,
allow_na = FALSE,
min_length = -Inf,
max_length = Inf,
check_type,
convert_if_possible,
dont_assign = FALSE
)
arg_name |
the argument |
allow_more_than_one |
allow vectors |
allow_null |
allow NULL |
allow_na |
allow |
min_length |
minimum length of the argument's value |
max_length |
maximum length of the argument's value |
check_type |
a predicate function, that must return |
convert_if_possible |
if given, a lambda can be given
similar to |
dont_assign |
set |
the value of arg_name – but this is updated in the calling frame anyway.
## Not run:
f <- function(x) {
util_expect_scalar(x, check_type = is.integer)
}
f(42L)
try(f(42))
g <- function(x) {
util_expect_scalar(x, check_type = is.integer, convert_if_possible =
as.integer)
}
g(42L)
g(42)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.