Check if argument is a positive integer or numeric.
Usage
check_scalar_sign(
x,
arg_sign = "positive",
arg_equal = FALSE,
alt_null = FALSE,
add_msg = NULL
)Arguments
- x
Function argument that is being asserted. Needs to be an integer or a numeric scalar.
- arg_sign
Character. It can take value
"positive"or"negative".- arg_equal
Logical. If
TRUEit will include0as a valid option ( in other words it will check ifxis non negative or non positive).- alt_null
Logical. Should argument accept
NULLvalue.- 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_names}in the message body (e.g. "What are the {x_names}");pass the tested sign by using
{arg_sign}in the message body (e.g. "I want them to be {arg_sign})".
Examples
pi <- 4L
pn <- 21.37
ni <- -666L
nn <- -505.606
pi2 <- c(2L, 18L)
pn2 <- c(85.86, 11.09)
ni2 <- c(-123L, -66L)
nn2 <- c(-3.14, -0.001)
zi1 <- 0
if (FALSE) { # \dontrun{
check_scalar_sign(pi, arg_sign = "negative")
check_scalar_sign(nn, arg_sign = "positive")
check_scalar_sign(pn2, arg_sign = "negative", alt_null = TRUE)
check_scalar_sign(ni, arg_sign = "positive",
add_msg = "{.arg {x_name}} is not {.val {arg_sign}}"
)
check_scalar_sign(zi1, arg_sign = "positive", arg_equal = TRUE)
check_scalar_sign(zi1, arg_sign = "negative", arg_equal = TRUE)
check_scalar_sign(zi1, arg_sign = "positive", arg_equal = FALSE)
check_scalar_sign(
zi1, arg_sign = "negative", arg_equal = FALSE, alt_null = TRUE
)
} # }