Skip to contents

Removes every column from x that is not listed in the var_spec for dataset. Equivalent to the drop step inside apply_spec(), exposed for standalone use.

Usage

drop_unspec_vars(x, spec, dataset)

Arguments

x

A data frame.

spec

A herald_spec object or a path to a spec file.

dataset

Character. The dataset name.

Value

The data frame with unspecified columns removed (invisibly).

Examples

spec <- herald_spec(
  ds_spec = data.frame(dataset = "DM", label = "Demographics",
                       stringsAsFactors = FALSE),
  var_spec = data.frame(dataset = "DM", variable = c("STUDYID", "AGE"),
                        stringsAsFactors = FALSE)
)
dm <- data.frame(STUDYID = "S1", AGE = 65L, EXTRA = "x",
                 stringsAsFactors = FALSE)
result <- drop_unspec_vars(dm, spec, "DM")
#> Dropped 1 variable: `EXTRA`
names(result)  # "STUDYID" "AGE"
#> [1] "STUDYID" "AGE"