| set_meta | R Documentation |
Stamp a artoo_meta onto a data frame as a single Dataset-JSON string in
its metadata_json attribute. Every write_*() codec reads that string
back with get_meta() and embeds it verbatim, so the metadata survives
the trip to any format. Use it to attach metadata to a bare frame before a
write, or to re-stamp after a tidyverse verb has dropped attributes.
set_meta(x, meta)
x |
The data frame to stamp. |
meta |
The metadata to attach. |
The data frame x, with its metadata_json attribute set. Pass
it on to a write_*() codec or back through get_meta().
get_meta() for the read half; apply_spec() which stamps it.
# ---- Example 1: re-stamp metadata a dplyr verb would drop ----
#
# Conform a dataset, capture its metadata, then re-attach after an
# attribute-dropping transform so the write stays lossless.
spec <- artoo_spec(
cdisc_adam_datasets, cdisc_adam_variables,
codelists = cdisc_codelists
)
adsl <- apply_spec(cdisc_adsl, spec, "ADSL")
meta <- get_meta(adsl)
trimmed <- head(as.data.frame(adsl), 5)
attr(trimmed, "metadata_json") <- NULL
set_meta(trimmed, meta)
# ---- Example 2: borrow metadata from a conformed dataset ----
#
# A writer with a raw frame can lift metadata off a conformed dataset and
# stamp it onto the bare frame (DM is SDTM, so its spec is sdtm-shaped).
sdtm <- artoo_spec(
cdisc_sdtm_datasets, cdisc_sdtm_variables,
codelists = cdisc_codelists
)
meta_dm <- get_meta(apply_spec(cdisc_dm, sdtm, "DM"))
dm <- set_meta(cdisc_dm, meta_dm)
is_artoo_meta(get_meta(dm))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.