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.
See also
Other specification:
apply_spec(),
coerce_types(),
decode_var(),
detect_adam_class(),
detect_adam_classes(),
herald_spec(),
order_cols(),
read_spec(),
read_spec_define(),
scaffold_vars(),
sort_keys(),
spec_codelist(),
spec_datasets(),
spec_study(),
spec_vars(),
write_define_html(),
write_define_xml(),
write_spec()
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"
