is_empty | R Documentation |
This function checks whether a string or character vector (of length 1), a list or any vector (numeric, atomic) is empty or not.
is_empty(x, first.only = TRUE, all.na.empty = TRUE)
x |
String, character vector, list, data.frame or numeric vector or factor. |
first.only |
Logical, if |
all.na.empty |
Logical, if |
Logical, TRUE
if x
is a character vector or string and
is empty, TRUE
if x
is a vector or list and of length 0,
FALSE
otherwise.
NULL
- or NA
-values are also considered as "empty" (see
'Examples') and will return TRUE
, unless all.na.empty==FALSE
.
is_empty("test")
is_empty("")
is_empty(NA)
is_empty(NULL)
# string is not empty
is_empty(" ")
# however, this trimmed string is
is_empty(trim(" "))
# numeric vector
x <- 1
is_empty(x)
x <- x[-1]
is_empty(x)
# check multiple elements of character vectors
is_empty(c("", "a"))
is_empty(c("", "a"), first.only = FALSE)
# empty data frame
d <- data.frame()
is_empty(d)
# empty list
is_empty(list(NULL))
# NA vector
x <- rep(NA,5)
is_empty(x)
is_empty(x, all.na.empty = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.