evaluates empty elements in a vector

This function evaluates if an element in a vector is empty the na.empty argument allows for evaluating NA values (TRUE if NA) and all.na returns a TRUE if all elements are NA. The trim argument trims a character string to account for the fact that c(" ") is not empty but, a vector with c("") is empty. Using trim = TRUE will force both to return TRUE

is.empty(x, all.na = FALSE, na.empty = TRUE, trim = TRUE)

Arguments

x

A vector to evaluate elements

all.na

(FALSE / TRUE) Return a TRUE if all elements are NA

na.empty

(TRUE / FALSE) Return TRUE if element is NA

trim

(TRUE / FALSE) Trim empty strings

Value

A Boolean indicating empty elements in a vector, if all.na = FALSE a TRUE/FALSE value will be returned for each element in the vector

Author

Jeffrey S. Evans <jeffrey_evans@tnc.org>

Examples

is.empty( c("") )
#> [1] TRUE
is.empty( c(" ") )
#> [1] TRUE
is.empty( c(" "), trim=FALSE )
#> [1] FALSE
is.empty( c("",NA,1) )
#> [1] TRUE TRUE FALSE
is.empty( c("",NA,1), na.empty=FALSE)
#> [1] TRUE NA FALSE
is.empty( c(NA,NA,NA) )
#> [1] TRUE TRUE TRUE
is.empty( c(NA,NA,NA), all.na=TRUE )
#> [1] TRUE
is.empty( c(NA,2,NA), all.na=TRUE )
#> [1] FALSE
any( is.empty( c("",2,3) ) )
#> [1] TRUE
any( is.empty( c(1,2,3) ) )
#> [1] FALSE