Check the range of values and the length of input vectors before used in control flow or passed to C++ functions.
check_integer(
x,
min_len = 1,
max_len = 1,
min = -Inf,
max = Inf,
strict = FALSE,
allow_null = FALSE
)
check_double(
x,
min_len = 1,
max_len = 1,
min = -Inf,
max = Inf,
strict = FALSE,
allow_null = FALSE
)
check_logical(
x,
min_len = 1,
max_len = 1,
strict = FALSE,
allow_null = FALSE,
allow_na = FALSE
)
check_character(
x,
min_len = 1,
max_len = 1,
min_nchar = 0,
max_nchar = Inf,
strict = FALSE,
allow_null = FALSE
)
minimum length of the vector
maximum length of the vector
minimum value in the vector
maximum value in the vector
raise error when x
is a different type
if TRUE
, returns NULL
when is.null(x)
if TRUE
, convert NA
to FALSE
minimum character length of values in the vector
maximum character length of values in the vector
Note that value checks are performed after coercion to expected input types.
if (FALSE) {
check_integer(0, min = 1) # error
check_integer(-0.1, min = 0) # return 0
check_double(-0.1, min = 0) # error
check_double(numeric(), min_len = 0) # return numeric()
check_double("1.1", min = 1) # returns 1.1
check_double("1.1", min = 1, strict = TRUE) # error
check_double("xyz", min = 1) # error
check_logical(c(TRUE, FALSE), min_len = 3) # error
check_character("_", min_nchar = 1) # return "_"
check_character("", min_nchar = 1) # error
}