compact: Drop NULL elements from a list

View source: R/map.R

compactR Documentation

Drop NULL elements from a list

Description

Remove every NULL element of .x, keeping the rest (including other falsy-but-not-NULL values like NA, 0, or ""). The common companion to map() when some calls legitimately return nothing – e.g. an empty API response – and the NULLs must be dropped before foldr(), rbindfill(), or similar.

Usage

compact(.x)

Arguments

.x

A list.

Value

.x with its NULL elements removed.

Examples

compact(list(1, NULL, 2, NULL, 3))
compact(list(a = 1, b = NULL, c = NA))

basetable documentation built on Sept. 18, 2026, 9:13 a.m.