is_character_vector {chinese.misc}R Documentation

A Convenient Version of is.character

Description

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.

Usage

is_character_vector(x, len = NULL, allow_all_na = TRUE)

Arguments

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 len, the function still returns FALSE. The default is NULL, which means any length is OK.

allow_all_na

for length>1 character vector whose elements are all NA, if this argument is FALSE, then the function returns FALSE, if this argument is TRUE (default), then returns TRUE.

Details

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:

Value

TRUE or FALSE.

Examples

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))

[Package chinese.misc version 0.2.3 Index]