remove_empty_columns: Remove empty columns

View source: R/tools.R

remove_empty_columnsR Documentation

Remove empty columns

Description

Removes columns that contain only NA values from a data.table. Columns listed in excl_cols are retained even if they are empty.

Usage

remove_empty_columns(df, excl_cols = NULL, ...)

Arguments

df

A data.table from which empty columns should be removed.

excl_cols

Optional character vector of column names that must be preserved, even if all values in those columns are missing.

...

Additional arguments passed to methods.

Value

A data.table containing all original non-empty columns, plus any columns listed in excl_cols, regardless of whether they are empty. Columns that contain only NA values and are not explicitly preserved are removed from the output.

Examples

dt <- data.table::data.table(
  c = c(2, 2, 2),
  x = c(NA, NA, NA),
  y = c(NA, NA, NA)
)
remove_empty_columns(dt, excl_cols = "y")

ume documentation built on Dec. 13, 2025, 1:06 a.m.