Pull the artoo_meta off a data frame produced by apply_spec() or read
back by any read_*() codec. The metadata travels as a single
Dataset-JSON string in the frame's metadata_json attribute; get_meta()
parses it to the S7 object, the form every codec writes from. This is the
read half of the lossless round-trip.
Arguments
- x
A data frame carrying artoo metadata.
<data.frame>: required. Typically the output ofapply_spec()or aread_*()codec.Requirement:
xmust carry ametadata_jsonattribute (set byset_meta(),apply_spec(), or a reader); a bare frame aborts withartoo_error_input.
Value
A <artoo_meta> with two properties. @dataset is a named
list of dataset-level attributes: itemGroupOID, name, label,
records, studyOID, metaDataVersionOID, encoding, and keys.
@columns is a named list with one entry per variable, each carrying
itemOID, name, label, dataType, targetDataType, length,
displayFormat, informat, keySequence, codelist,
significantDigits, and origin (absent values are NULL). Pass it
to set_meta() to re-attach, or index it directly
(meta@columns$AGE$label).
See also
set_meta() for the write half; apply_spec() which stamps it.
Examples
# ---- Example 1: read metadata off a conformed dataset ----
#
# apply_spec() stamps the metadata; get_meta() reads it back as the S7
# object whose @columns holds one CDISC attribute set per variable.
spec <- artoo_spec(cdisc_adam_datasets, cdisc_adam_variables, codelists = cdisc_codelists)
adsl <- apply_spec(cdisc_adsl, spec, "ADSL")
meta <- get_meta(adsl)
meta@columns$STUDYID
#> $itemOID
#> [1] "IT.ADSL.STUDYID"
#>
#> $name
#> [1] "STUDYID"
#>
#> $label
#> [1] "Study Identifier"
#>
#> $dataType
#> [1] "string"
#>
#> $length
#> [1] 12
#>
# ---- Example 2: round-trip metadata across two frames ----
#
# The metadata is a portable object: read it off one frame and stamp it
# onto another with set_meta().
bare <- as.data.frame(adsl)
attr(bare, "metadata_json") <- NULL
restamped <- set_meta(bare, meta)
identical(get_meta(restamped)@columns, meta@columns)
#> [1] TRUE