Skip to contents

Check that x is a character vector of the correct length with only allowed character values.

Usage

all_characters(x, allow_empty = FALSE, allow_zero = FALSE, allow_NA = FALSE)

is_character(x, allow_empty = FALSE, allow_zero = FALSE, allow_NA = FALSE)

Arguments

x

object to test.

allow_empty

TRUE or FALSE: allow empty strings ("") in x?

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 character vector of the correct length with only allowed character values.

Notes

all_characters() and is_character() by default return FALSE for empty strings.

See also

The vignettes about design choices and about type coercion.

Other collections of checks on type and length: all_names(), is_logical(), is_natural(), is_number(), is_zerolength()

Examples

is_character("a") # TRUE
#> [1] TRUE
is_character(c("a", "b")) # FALSE: incorrect length
#> [1] FALSE
all_characters(c("a", "b")) # TRUE
#> [1] TRUE
is_character(1) # FALSE: incorrect type
#> [1] FALSE
is_character(NA_character_) # FALSE: default 'allow_NA' is FALSE
#> [1] FALSE
is_character(NA_character_, allow_NA = TRUE) # TRUE
#> [1] TRUE
is_character(NA, allow_NA = TRUE) # FALSE: incorrect type
#> [1] FALSE