| set_type | R Documentation |
Return a new artoo_spec with one or more variables retyped. This is the
supported, in-R way to correct a spec when the data disagrees with its
declared dataType (e.g. a variable typed integer whose extract holds
fractional values): fix it here rather than editing the source workbook,
then drive apply_spec() with the corrected spec. The spec is immutable,
so the original is never changed.
set_type(spec, dataset, ...)
spec |
The specification to amend. |
dataset |
The dataset whose variables to retype. |
... |
Named Tip: to undo an |
Per-dataset scope. A type is set only on the named dataset's row.
A variable that appears in several datasets keeps its other rows' types;
call set_type() once per dataset to change them all. Spec-wide
consequences (a variable typed inconsistently across datasets) are a
validate_spec() concern, not a construction error here.
Canonicalised, then validated. Each supplied type is mapped through
the closed CDISC dataType vocabulary, so "Float", "decimal", and
"text" all resolve; an unrecognised token aborts with
artoo_error_type. The rebuilt spec is re-validated, so an override that
would break the spec aborts with artoo_error_spec.
A new <artoo_spec> with the named variables retyped, ready for
apply_spec() or write_spec(). The input spec is unchanged.
Auto-repair: repair_spec() to apply every integer_fraction /
integer_overflow fix from a findings frame at once.
Workflow: apply_spec() to conform with the corrected spec;
write_spec() to persist it; check_spec() to find the mismatches.
# ---- Example 1: retype one variable the data disagrees with ----
#
# The bundled adam_spec types ADSL.AGE as integer. If an extract stored it
# with fractional values, retype it to float so apply_spec() coerces
# without loss. set_type() returns a new spec; the original is untouched.
fixed <- set_type(adam_spec, "ADSL", AGE = "float")
v <- spec_variables(fixed, "ADSL")
v[v$variable == "AGE", c("variable", "data_type")]
# ---- Example 2: retype several at once, original left intact ----
#
# Pass any number of variable = type pairs; canonical dataTypes and common
# spellings both resolve. The source spec is immutable, so adam_spec still
# reports AGE as its original type.
patched <- set_type(adam_spec, "ADSL", AGE = "decimal", TRTSDT = "date")
spec_variables(adam_spec, "ADSL")$data_type[
spec_variables(adam_spec, "ADSL")$variable == "AGE"
]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.