Sorts x by the key variables defined in ds_spec$keys for
dataset, equivalent to SAS PROC SORT BY on those variables.
Sets the herald.sort_keys attribute on the result so that
write_xpt() and write_json() can verify sort
order without re-sorting. No-op (with no error) when no keys are defined.
See also
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(),
scaffold_vars(),
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",
keys = "STUDYID, USUBJID",
stringsAsFactors = FALSE
),
var_spec = data.frame(
dataset = "DM",
variable = c("STUDYID", "USUBJID"),
stringsAsFactors = FALSE
)
)
dm <- data.frame(
STUDYID = c("S1", "S1"),
USUBJID = c("001-002", "001-001"),
stringsAsFactors = FALSE
)
result <- sort_keys(dm, spec, "DM")
result$USUBJID # "001-001" "001-002"
#> [1] "001-001" "001-002"
attr(result, "herald.sort_keys") # "STUDYID" "USUBJID"
#> [1] "STUDYID" "USUBJID"
