is_empty: Test whether an object is *empty*

View source: R/utils_validation.R

is_emptyR Documentation

Test whether an object is *empty*

Description

This lightweight helper mimics the behaviour of 'pracma::isempty()' but depends only on base R. An object is considered *empty* when it contains no data: * 'NULL' * an atomic vector, matrix, array or factor of length 0 * a list (including named lists) of length 0 * a data frame with zero rows ('nrow == 0')

Usage

is_empty(x)

Arguments

x

Any R object.

Details

The function is deliberately strict - environments, functions, S4/R6 objects, etc. are **not** treated as empty. If you need additional classes to be regarded as empty you can extend the internal checks.

Value

A logical scalar ('TRUE' if 'x' is empty, 'FALSE' otherwise).

Examples

## Not run: 
is_empty(NULL) # TRUE
is_empty(numeric(0)) # TRUE
is_empty(list()) # TRUE
is_empty(data.frame()) # TRUE
is_empty(1:5) # FALSE
is_empty(list(a = 1)) # FALSE
is_empty(data.frame(x = 1)) # FALSE

## End(Not run)

TesiproV documentation built on Oct. 28, 2026, 5:13 p.m.