inspect_true_or_false {inspector} | R Documentation |
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. |
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:
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 oflength
1.An informative error message is thrown otherwise.
See Also
-
inspect_character
to validate character vectors. -
inspect_character_match
to validate character vectors with predefined allowed values.
Examples
# 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]]))
[Package inspector version 1.0.3 Index]