Description Usage Arguments Details Value See Also Examples
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.
1 |
x |
An arbitrary object. |
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
.
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.
inspect_character
to validate character vectors.
inspect_character_match
to validate character
vectors with predefined allowed values.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # 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]]))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.