read_define.RdParses a Define-XML 2.1 file back into a define21_spec. The result is
rebuilt through define_spec(), so it is validated on the way in and a
write_define() / read_define() round trip compares equal.
read_define(path)A define21_spec object.
Constructs this package does not write are also not read: analysis results
metadata (ARM), annotated-CRF and supplemental document leaves, Alias,
def:DocumentRef/def:PDFPageRef, SignificantDigits and ItemDef-level
RangeCheck in the input file are ignored rather than half-parsed. Value
level metadata (def:ValueListDef, def:WhereClauseDef) and
ExternalCodeList are read, because this version writes them.
Which dataset and variable a def:ValueListDef or a def:WhereClauseDef
belongs to is taken from the reference graph - ItemGroupDef ->
ItemRef -> ItemDef -> def:ValueListRef - rather than from the text of
the OIDs, because documents in the wild use OID schemes this package does
not (VL.AETERM names no dataset at all). Only when nothing in the document
references a value list is its OID read as VL.<dataset>.<variable>.
Two consequences worth knowing:
An ItemDef shared by several ItemGroupDefs is attributed to the first
that references it, because a define21_spec describes variables per
dataset. Writing such a document back expands the shared ItemDef into
one per dataset.
The value key of each value comes from the ItemOID with the
IT.<dataset>.<variable>. prefix removed; an ItemOID that does not carry
that prefix keeps its whole tail, so nothing is silently dropped.
f <- write_define(define21_example()$spec, tempfile(fileext = ".xml"))
spec <- read_define(f)
spec$datasets$dataset
#> [1] "DM" "AE" "VS"