TODO.
Arguments
- x
Function arguments that are being asserted.
- arg_length
Integer. Length of argument, for scalars it should take value
1(default).- alt_null
Logical. Should argument accept NULL value.
- add_msg
Is an additional message that can be printed over the standard function error message. You can:
pass the names of the arguments that failed the test by using
{x_name}in the message body (e.g. "What are the {wrong_names}");pass the tested length by using
{arg_length}in the message body (e.g. "I want them to be {arg_length})"pass the lengths of the arguments that failed the test by using
{wrong_length}in the message body (e.g. "{wrong_lengths} are wrong")
Examples
x1 <- 2
x2 <- c("x", "y")
nl1 <- NULL
if (FALSE) { # \dontrun{
check_length(x1, arg_length = 1L)
check_length(x2, arg_length = 1L)
check_length(x1, arg_length = 2L)
check_length(
x1, arg_length = 2L, add_msg = "{.arg {x_name}} should be short"
)
check_length(
x1, arg_length = 2L, alt_null = TRUE, add_msg = "{.arg {x_name}} should be short"
)
check_length(
nl1, arg_length = 2L, alt_null = TRUE, add_msg = "{.arg {x_name}} should be short"
)
} # }