Skip to contents

Check if an argument is single TRUE or FALSE. As an option it is possible to allow NULL value when alt_null = TRUE.

Usage

check_bool(x, alt_null = FALSE, add_msg = NULL)

Arguments

x

Function argument that is being asserted.

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 {x_name}");

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

Value

If argument is single TRUE or FALSE (optionally NULL) it returns invisible NULL. Otherwise the function throws an error.

Examples

c1 <- c("x", "y")
n1 <- c(1,3,4)
n2 <- c(1.5, 2.5)
i1 <- 1L
nl1 <- NULL
l1 <- FALSE
l2 <- c(FALSE, TRUE)
if (FALSE) { # \dontrun{
check_bool(c1)
check_bool(nl1)
check_bool(nl1, alt_null = TRUE)
check_bool(n2, alt_null = TRUE)
check_bool(i1)
check_bool(l1)
check_bool(l2)
} # }