Learn R Programming

inspector (version 1.0.3)

inspect_true_or_false: Validate non-missing logical values

Description

inspect_true_or_false checks if an object is a non-missing logical vector of length 1. This can be useful to validate inputs in user-defined functions.

Usage

inspect_true_or_false(x)

Arguments

x

An arbitrary object.

Value

inspect_true_or_false does not return any output. There are two possible scenarios:

  • The call is silent if x is a non-missing logical vector of length 1.

  • An informative error message is thrown otherwise.

Details

inspect_true_or_false conducts a series of tests to check if x is a non-missing logical vector of length 1. Namely, inspect_true_or_false checks if:

  • x is NULL or empty.

  • x is an atomic vector of length 1.

  • The typeof x is logical.

  • x is NA or NaN.

See Also

Examples

Run this code
# NOT RUN {
# Calls that pass silently:
x <- TRUE
y <- FALSE
inspect_true_or_false(x)
inspect_true_or_false(y)

# Calls that throw informative error messages:
mylist <- list(NULL, NA, NaN, 1, 0, "TRUE")
try(inspect_true_or_false(mylist[[1]]))
try(inspect_true_or_false(mylist[[2]]))
try(inspect_true_or_false(mylist[[3]]))
try(inspect_true_or_false(mylist[[4]]))
try(inspect_true_or_false(mylist[[5]]))
try(inspect_true_or_false(mylist[[6]]))
# }

Run the code above in your browser using DataLab