Checks if an object is empty (e.g: of zero length) and returns TRUE/FALSE

is.empty(x, mode = NULL, ...)

Arguments

x

an object

mode

is the object an empty (zero length) object of this mode (can be "integer", "numeric", and so on...)

...

none are available.

Source

https://stackoverflow.com/questions/6451152/how-to-catch-integer0

Value

Returns TRUE/FALSE if the object is empty or not.

Details

Uses identical and avoids any attribute problems by using the fact that it is the empty set of that class of object and combine it with an element of that class.

See also

Author

James (https://stackoverflow.com/users/269476/james)

Examples

is.empty(integer(0)) #TRUE
#> [1] TRUE
is.empty(0L) #FALSE
#> [1] FALSE
is.empty(numeric(0)) #TRUE
#> [1] TRUE
is.empty(NA) # FALSE
#> [1] FALSE
is.empty(FALSE) # FALSE
#> [1] FALSE
is.empty(NULL) # FALSE (with a warning)
#> Warning: x is NULL
#> [1] FALSE
a <- which(1:3 == 5) b <- numeric(0) is.empty(a)
#> [1] TRUE
is.empty(a,"numeric")
#> [1] FALSE
is.empty(b)
#> [1] TRUE
is.empty(b,"integer")
#> [1] FALSE