is_empty: is_empty

View source: R/is_empty.R

is_emptyR Documentation

is_empty

Description

Logical test for all the different versions of empty values, i.e.:

  • NULL

  • ""

  • NA

  • "⁠\\n⁠"

  • list()

  • length(x)==0

Usage

is_empty(x, names_meaningful = FALSE)

Arguments

x

any value or vector

names_meaningful

logical, if T, when an empty data frame or list is supplied for x that is all NA, but has names, it will return FALSE. default= FALSE

Details

Works on values, vectors, or a flat list. For vector and list inputs output will be a single T or F, not a vector of T/F values.

Value

TRUE (if empty) or FALSE (if not empty)

logical T=Empty, F=Not empty

Examples

is_empty("")
is_empty(3)
is_empty(c("",NA,NULL))
is_empty(list(a="",b=NA,c=NULL))
is_empty(list(a="",b=NA,c="nonempty cell"))

b <- dplyr::tibble(ImportantColumn=NA,ImportantColumn2=NA)
is_empty(b)
#Here, if we care about column names and don't consider this
#empty, we should return FALSE
is_empty(b, names_meaningful=TRUE)

is_empty(list(a=NA,b=b,c=list(),d=NULL))
is_empty(list(a=NA,b=b,c=list(),d=NULL), names_meaningful=TRUE)
is_empty(data.frame(a=NA,b=NA))

#

galacticpolymath/GPpub documentation built on April 5, 2025, 6:04 p.m.