Adds every variable defined in the var_spec for dataset
that is absent from x as a correctly typed NA column.
Existing columns are unchanged. Equivalent to the scaffold step inside
apply_spec(), exposed for standalone use.
See also
apply_spec(), drop_unspec_vars()
Other specification:
apply_spec(),
coerce_types(),
decode_var(),
detect_adam_class(),
detect_adam_classes(),
drop_unspec_vars(),
herald_spec(),
order_cols(),
read_spec(),
read_spec_define(),
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"),
data_type = c("text", "integer"),
stringsAsFactors = FALSE
)
)
dm <- data.frame(STUDYID = "S1", stringsAsFactors = FALSE)
result <- scaffold_vars(dm, spec, "DM")
#> Scaffolded 1 variable: `AGE`
names(result) # "STUDYID" "AGE"
#> [1] "STUDYID" "AGE"
is.na(result$AGE) # TRUE
#> [1] TRUE
