Metadata checks - Check if a collection is empty
is_empty2.RdIs a collection object (see is_collection()) empty, i.e. has zero length?
Similar to rlang::is_empty(), but yields an error for non-collections,
including NULL by default.
Note that objects of type 'S4' and 'object' are not considered collections, even if they are 'filled' with slots/attributes.
Examples
is_empty2(list()) #> TRUE
#> [1] TRUE
is_empty2(list(1)) #> FALSE
#> [1] FALSE
is_empty2(list(NULL)) #> FALSE
#> [1] FALSE
is_empty2(character(0)) #> TRUE
#> [1] TRUE
is_empty2(letters) #> FALSE
#> [1] FALSE
# Only works for collections (see ?is_collection()):
try(is_empty2(sum))
#> Error in is_empty2(sum) : `x` is not a collection.
#> Error in is_empty2(sum) : `x` is not a collection.
# But can be made to work with NULL:
is_empty2(NULL, null = TRUE) #> TRUE
#> [1] TRUE