is_empty: Check if a vecotr is empty or not.

View source: R/is_empty.R

is_emptyR Documentation

Check if a vecotr is empty or not.

Description

There's no function in base R that checks if a vector is empty or not. The function is.null() doesn't always work, for example, is.null(c()) returns TRUE (correct), but is.null(vector()) returns FALSE (incorrect), is.null(numeric(0)) returns FALSE (incorrect), is.null(integer(0)) returns FALSE (incorrect), is.null(character(0)) returns FALSE (incorrect). A non-empty vector, after removing each of its elements, will become a vector of length 0. So we can check if a vector is empty by its length. If its length is 0, then it's empty.

Usage

is_empty(xs)

Arguments

xs

A vector of any type.

Value

TRUE if the vector is empty, FALSE otherwise.

Examples

is_empty(vector()) # vector() is the same as logical()
is_empty(numeric())
is_empty(integer())
is_empty(character())
is_empty(c())

cabaceo/shinymod documentation built on Sept. 8, 2023, 12:23 p.m.