Skip to contents

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

Usage

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

Arguments

x

object to test.

allow_zero

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

allow_NA

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

Value

TRUE or FALSE indicating if x is a length-one logical vector only containing allowed logical values.

See also

The vignette about design choices.

Other collections of checks on type and length: all_characters(), all_names(), is_natural(), is_number(), 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