Build and validate a artoo_spec from dataset, variable, and codelist
tables. Each table is coerced to a plain data frame, missing optional
columns are filled with typed NAs, every variable type is canonicalised
to the CDISC dataType vocabulary, and cross-slot integrity (dataset and
codelist references) is checked before the object is returned. The spec
is the lingua franca the rest of artoo reads, applies, and serialises.
Usage
artoo_spec(
datasets = NULL,
variables = NULL,
codelists = NULL,
study = NULL,
values = NULL,
methods = NULL,
comments = NULL,
documents = NULL,
standard = NULL,
standards = NULL,
where_clauses = NULL,
method_expressions = NULL,
arm_displays = NULL,
arm_results = NULL,
dictionaries = NULL
)Arguments
- datasets
Dataset-level metadata table.
<data.frame>: required. One row per dataset; must carry adatasetcolumn. Optional columnslabel,class,structure,keysare filled withNAwhen absent.- variables
Variable-level metadata table.
<data.frame>: required. One row per variable; must carrydataset,variable, anddata_type. Thedata_typecolumn is canonicalised to a CDISCdataType(e.g."text"becomes"string").Requirement: every
datasetvalue must appear indatasets.- codelists
Controlled-terminology terms.
<data.frame> | NULL. Must carrycodelist_idandtermwhen supplied.Interaction: every
codelist_idreferenced byvariablesmust resolve here.- study
Study-level metadata.
<data.frame> | NULL. A single row of named study fields. Well-known fields are canonicalised tostudy_name,study_description, andprotocol_name(aliases such asStudyNameorstudyidresolve automatically); other fields pass through verbatim. Astandardfield, when present, is consumed into@standard.- values
Value-level (VLM) metadata.
<data.frame> | NULL.- methods
Derivation methods.
<data.frame> | NULL. The Define-XML method definitions variables reference bymethod_id; must carrymethod_idwhen supplied. Completeness (e.g. a referenced method has a description) is checked byvalidate_spec(), not here.- comments
Comment definitions.
<data.frame> | NULL. Referenced bycomment_id; must carrycomment_idwhen supplied.- documents
Document references.
<data.frame> | NULL. Referenced bydocument_id; must carrydocument_idwhen supplied.- standard
The primary CDISC standard the spec implements.
<character(1)> | NULL. E.g."ADaMIG 1.1"or"SDTMIG 3.2". WhenNULL(default) it is resolved fromstudy$standard, or from the value most rows ofdatasets$standardname; absent everywhere,@standardisNA.Restriction: an explicit value that matches nothing the source names aborts with
artoo_error_spec.- standards
CDISC standards this spec claims.
<data.frame> | NULL. Must carrystandard_id,nameandversion. Define-XML 2.1 emits these as adef:Standardsblock that datasets and codelists reference by id; 2.0 has room for only one, taken from the row flaggedis_primary.- where_clauses
Structured value-level conditions.
<data.frame> | NULL. Must carrywhere_clause_idandcomparator. One row per check value, because a check value is free text and may itself contain a comma, so any collapsed form would be lossy.- method_expressions
Formal expressions for derivation methods.
<data.frame> | NULL. Must carrymethod_id. A separate table because a method may carry several expressions in different languages, which extra rows onmethodscould not express without changing what the published one-row-per-method rule means.- arm_displays
Analysis result displays.
<data.frame> | NULL. Must carrydisplay_id. Analysis Results Metadata is version-neutral: the vocabulary is identical for Define-XML 2.0 and 2.1.- arm_results
Analysis results.
<data.frame> | NULL. Must carrydisplay_idandresult_id. One row per result and analysis dataset, since each analysis dataset carries its own where-clause reference.- dictionaries
External codelists.
<data.frame> | NULL. Must carrydictionary_id. A terminology too large to enumerate, named rather than listed: MedDRA, WHODrug, ISO 3166. Both readers populate it, and a variable points at one from the samecodelist_idcolumn it would use for an enumerated list.
Value
A validated artoo_spec object. Inspect it with
spec_datasets() / spec_variables(), or check it with
validate_spec().
Details
Coerce, then validate. Each table is first coerced to a plain data
frame (a tibble is accepted and demoted); known columns are cast to
their storage mode and absent optional columns are added as typed NA,
so every downstream reader can trust the schema. Validation runs only
after coercion, on the completed slots.
Type canonicalisation. variables$data_type is mapped through the
closed CDISC dataType vocabulary (string, integer, decimal,
float, double, boolean, date, datetime, time, URI). Common
SAS / P21 spellings resolve automatically ("text", "Char",
"integer (8)", ...); an unrecognised token aborts with
artoo_error_type.
Cross-slot integrity. Construction fails (artoo_error_spec) if a
variable names a dataset absent from datasets, or references a
codelist_id absent from codelists.
One primary standard, linked per dataset. The scalar @standard
property holds the spec's primary CDISC standard, resolved from the
standard argument, a standard column in datasets (the P21 workbook
shape), and a standard field in study (the Define-XML shape) — those
columns are consumed, so @standard is the single home. A datasets
column naming several standards is legitimate (a study may mix
implementation-guide versions): each row is linked to its standard via
datasets$standard_id, minting a standards row where none defines the
name, and @standard takes the study's stated standard, or failing that
the one most datasets name. An explicit standard argument contradicting
every value in the source aborts with artoo_error_spec.
One study vocabulary. Well-known study fields are canonicalised to
the CDISC ODM GlobalVariables names, snake_cased: study_name,
study_description, protocol_name. Source spellings resolve
automatically (StudyName, studyid, ...); fields the vocabulary does
not know pass through verbatim. Aliases that disagree on a value abort
with artoo_error_spec.
See also
Inspect: spec_datasets(), spec_variables(), spec_codelists(),
spec_keys(), spec_study().
Check: validate_spec(). Predicate: is_artoo_spec().
Examples
# ---- Example 1: build a spec from the bundled CDISC-pilot tables ----
#
# `cdisc_sdtm_datasets` and `cdisc_sdtm_variables` hold the CDISC pilot SDTM
# metadata in the shape artoo_spec() expects; the constructor
# canonicalises every type and checks cross-slot integrity.
spec <- artoo_spec(cdisc_sdtm_datasets, cdisc_sdtm_variables, codelists = cdisc_codelists)
spec_datasets(spec)
#> [1] "DM"
# ---- Example 2: a focused spec for a single dataset ----
#
# Slice the bundled tables to one dataset (DM) to build a smaller spec.
dm_ds <- cdisc_sdtm_datasets[cdisc_sdtm_datasets$dataset == "DM", ]
dm_var <- cdisc_sdtm_variables[cdisc_sdtm_variables$dataset == "DM", ]
dm_spec <- artoo_spec(dm_ds, dm_var, codelists = cdisc_codelists)
head(spec_variables(dm_spec, "DM")[, c("variable", "label", "data_type")])
#> variable label data_type
#> 1 STUDYID Study Identifier string
#> 2 DOMAIN Domain Abbreviation string
#> 3 USUBJID Unique Subject Identifier string
#> 4 SUBJID Subject Identifier for the Study string
#> 5 RFSTDTC Subject Reference Start Date/Time string
#> 6 RFENDTC Subject Reference End Date/Time string