Reorders the columns of x to match the variable order defined in
the var_spec for dataset (by the order column if
present, otherwise by row order). Columns not in the spec trail at the
end with a warning. Equivalent to the order step inside
apply_spec(), exposed for standalone use.
See also
Other specification:
apply_spec(),
coerce_types(),
decode_var(),
detect_adam_class(),
detect_adam_classes(),
drop_unspec_vars(),
herald_spec(),
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", "USUBJID", "AGE"),
order = 1:3,
stringsAsFactors = FALSE
)
)
dm <- data.frame(AGE = 65L, USUBJID = "001", STUDYID = "S1",
stringsAsFactors = FALSE)
result <- order_cols(dm, spec, "DM")
names(result) # "STUDYID" "USUBJID" "AGE"
#> [1] "STUDYID" "USUBJID" "AGE"
