View source: R/codec_parquet.R
| write_parquet | R Documentation |
Serialize a data frame to an Apache Parquet (.parquet) file, storing the
data natively while preserving the full artoo_meta as a CDISC-shaped
sidecar in the file's key-value metadata. The emit end of the artoo
workflow (spec -> apply_spec -> write_parquet); a thin wrapper over
write_dataset() with format = "parquet". Requires the lightweight
nanoparquet package.
write_parquet(
x,
path,
encoding = NULL,
on_invalid = c("error", "translit", "fold", "replace", "ignore"),
compression = "snappy"
)
x |
The dataset to write. |
path |
Destination |
encoding |
Source charset to record. Tip: any SAS or IANA spelling listed by |
on_invalid |
Policy for values that are not valid UTF-8.
|
compression |
Column compression codec.
|
Metadata where plain Parquet has none. A bare nanoparquet/arrow file
drops labels, formats, and codelists; write_parquet() embeds the complete
artoo_meta as a single Dataset-JSON-shaped string under the
metadata_json key, so read_parquet() restores every CDISC attribute.
The same string is what a .json file or an rds carries, so conversion
between any two formats stays lossless. A reader without artoo still opens
the data and can see the metadata_json block.
The input x, invisibly, so a write can sit mid-pipeline.
read_parquet() for the inverse; write_dataset() for the
generic dispatcher.
spec <- artoo_spec(cdisc_adam_datasets, cdisc_adam_variables, codelists = cdisc_codelists)
# ---- Example 1: write a conformed dataset to Parquet ----
#
# apply_spec() attaches the metadata; write_parquet() stores the data
# natively and the metadata as a CDISC-shaped sidecar.
adsl <- apply_spec(cdisc_adsl, spec, "ADSL", conformance = "off")
path <- tempfile(fileext = ".parquet")
write_parquet(adsl, path)
# ---- Example 2: round-trip and confirm the metadata survived ----
#
# Reading it back yields an identical artoo_meta.
back <- read_parquet(path)
identical(get_meta(back)@columns, get_meta(adsl)@columns)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.