Skip to contents

Check that x is a length-one logical vector with only allowed values.

Usage

is_logical(x, allow_zerolength = FALSE, allow_NA = FALSE)

Arguments

x

object to check.

allow_zerolength

TRUE or FALSE: allow zero-length x of the correct type?

allow_NA

TRUE or FALSE: allow NA of the correct type in x?

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