Check that x is a length-one logical vector with only allowed values.
Arguments
- x
object to check.
- allow_zerolength
TRUEorFALSE: allow zero-lengthxof the correct type?- allow_NA
TRUEorFALSE: allow NA of the correct type inx?
Value
TRUE or FALSE indicating if x is a logical vector of the
correct length with only allowed values.
Details
is_logical() returns TRUE for logical-type x of length one, for
logical-type
zero-length x if allow_zerolength is TRUE, and for
logical-type NA if allow_NA is TRUE.
See also
Other collections of checks on type and length:
all_characters(),
all_names(),
is_natural(),
is_number(),
is_path(),
is_zerolength()
Examples
is_logical(TRUE) # TRUE
#> [1] TRUE
is_logical(c(TRUE, TRUE)) # FALSE: incorrect length
#> [1] FALSE
is_logical(1) # FALSE: incorrect type
#> [1] FALSE
is_logical(NA) # FALSE: default 'allow_NA' is FALSE
#> [1] FALSE
is_logical(NA, allow_NA = TRUE) # TRUE
#> [1] TRUE
is_logical(NA_character_, allow_NA = TRUE) # FALSE: incorrect type
#> [1] FALSE