Skip to contents

Check if an argument is NULL, if not checks if it is of expected value.

Usage

check_null_value(x, arg_value, add_msg = NULL)

Arguments

x

Function argument that is being asserted.

arg_value

Expected argument 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_names} in the message body (e.g. "What are the {x_names}");

  • pass the tested value by using {arg_value} in the message body (e.g. "I want them to be {arg_value})"

  • pass the values of the arguments that failed the test by using {wrong_value} in the message body (e.g. "{wrong_value} is wrong")

Value

If argument is of class returns invisible NULL, otherwise it throws an error.

Examples

c1 <- c("x", "y")
n1 <- c(1,3,4)
n2 <- c(1.5, 2.5)
i1 <- 1L
nl1 <- NULL
if (FALSE) { # \dontrun{
check_null_value(c1, arg_value = c("x", "y"))
check_null_value(nl1, arg_value = c("x", "y"))
check_null_value(n1, arg_value = c("a", "b", "c"))
check_null_value(n2, arg_value = c(1.5, 2.5, 3))
} # }