Write a data frame to an R .rds file, preserving its artoo_meta. A thin
wrapper over write_dataset() with format = "rds"; the rds carries the
metadata both as live R attributes and as the language-agnostic
metadata_json string, so read_rds() restores it exactly.
Arguments
- x
The dataset to write.
<data.frame>: required.- path
Destination
.rdspath.<character(1)>: required.- encoding
Source charset to record.
<character(1)> | NULL. rds is R-native and faithful: strings are saved as-is, never transcoded.encodingonly records the data's original charset in theartoo_meta, so a laterwrite_xpt()can reproduce the source bytes.NULL(default) leaves the recorded encoding untouched.Tip: any SAS or IANA spelling listed by
artoo_encodings()is accepted.
See also
read_rds() for the inverse; write_dataset() for the generic
dispatcher.
Examples
spec <- artoo_spec(cdisc_adam_datasets, cdisc_adam_variables, codelists = cdisc_codelists)
# ---- Example 1: write a conformed dataset to rds ----
#
# apply_spec() attaches the metadata; write_rds() carries it into the file.
adsl <- apply_spec(cdisc_adsl, spec, "ADSL", conformance = "off")
path <- tempfile(fileext = ".rds")
write_rds(adsl, path)
# ---- Example 2: round-trip and confirm the metadata survived ----
#
# Reading it back yields an identical artoo_meta.
back <- read_rds(path)
identical(get_meta(back)@columns, get_meta(adsl)@columns)
#> [1] TRUE