Description Usage Arguments Details Value Examples
View source: R/is_character_vector.R
This function checks to see if the object is a character vector. It is designed to have different
actions from is.character
and thus sometimes more convenient. See Details.
1 | is_character_vector(x, len = NULL, allow_all_na = TRUE)
|
x |
object to be checked |
len |
numeric vector represents the permitted length of character vector. If an
object is a character vector, but its length is not in |
allow_all_na |
for length>1 character vector whose elements are
all |
Sometimes we want to check if an object is a character vector. But is.character
cannot
do this, because it also returns TRUE
for a character matrix or data frame.
What's more, we usually not only want to see if an object is of class
character, but also want to see
if it is valid, that is, can be passed to other functions without errors. But is.character
even returns TRUE
for character(0)
.
Also, is.character(NA)
returns FALSE
, but
is.character(as.character(NA))
returns TRUE
, but in fact there is really
no difference between the two for users and many functions that do not allow NA
.
We list below the returns of is.character2
:
(1) if the object is NULL
, is.character2
returns FALSE
.
(2) if the object is of length 0, it always returns FALSE
.
(3) if the object is not vector, FALSE
.
(4) if it has only one element and this element is NA
, under all circumstances it
returns FALSE
.
(5) if the vector is of length>1, all the elements are NA
,
but the vector's class is not character, it returns FALSE
.
(6) if a character vector is of length>1, and all the elements
are NA
, then the result depends on argument allow_all_na
, if
allow_all_na = TRUE
, then TRUE
, otherwise, FALSE
.
TRUE
or FALSE
.
1 2 3 4 5 6 7 8 9 10 | is_character_vector(character(0))
is_character_vector(NA)
is_character_vector(as.character(NA))
is_character_vector(c(NA, NA))
is_character_vector(as.character(c(NA,NA)))
is_character_vector(as.character(c(NA, NA)), allow_all_na = FALSE)
is_character_vector(as.character(c(NA, NA)), allow_all_na = TRUE)
is_character_vector(matrix(c("a", "b", "c", "d"), nr = 2))
is_character_vector(c("a", "b", "c"), len = c(1, 10))
is_character_vector(c("a", "b", "c"), len = c(1:10))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.