is.empty {DIZtools}R Documentation

Check for empty/'NA'/'NULL'/'NaN'/etc. values.

Description

Rails-inspired helper that checks if vector values are "empty", i.e. if it's: NULL, zero-length, NA, NaN, FALSE, an empty string or 0. Note that unlike its native R is.<something> sibling functions, is.empty is vectorised (hence the "values").

Usage

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

Arguments

x

an object to check its emptiness

trim

trim whitespace? (TRUE by default)

all

return overall result over list/vector instead of vector of results? is.empty(x, all = TRUE) is the same like all(unlist(is.empty(x)))

...

additional arguments for sapply

Source

Copied from 'rapportools::is.empty()'

Examples

## Not run: 
is.empty(NULL)     # [1] TRUE
is.empty(c())      # [1] TRUE
is.empty(NA)       # [1] TRUE
is.empty(NaN)      # [1] TRUE
is.empty("")       # [1] TRUE
is.empty(0)        # [1] TRUE
is.empty(0.00)     # [1] TRUE
is.empty("    ")   # [1] TRUE
is.empty("foobar") # [1] FALSE
is.empty("    ", trim = FALSE)             # [1] FALSE
## is.empty is vectorised!
all(is.empty(rep("", 10)))                 # [1] TRUE
all(is.empty(matrix(NA, 10, 10)))          # [1] TRUE
is.empty(matrix(NA, 10, 10), all = TRUE))  # [1] TRUE

## End(Not run)

[Package DIZtools version 1.0.1 Index]