| write_ndjson | R Documentation |
Serialize a data frame to the newline-delimited variant of CDISC
Dataset-JSON v1.1 (.ndjson): line 1 carries the complete metadata block,
every following line one row array. The streaming end of the artoo
workflow (spec -> apply_spec -> write_ndjson) for datasets too large for
the array-form .json file; a thin wrapper over write_dataset() with
format = "ndjson".
write_ndjson(
x,
path,
on_invalid = c("error", "translit", "fold", "replace", "ignore"),
created = NULL,
strict = FALSE
)
x |
The dataset to write. |
path |
Destination |
on_invalid |
Policy for values that are not valid UTF-8.
|
created |
Creation timestamp. |
strict |
Suppress the |
Bounded memory, both directions. The writer streams slabs of
per-column JSON literals and read_ndjson() parses slab-sized line
batches, so a multi-million-row dataset never materializes a whole rows
array the way the .json codec must. A .ndjson.gz path gzips the stream
transparently.
The input x, invisibly, so a write can sit mid-pipeline.
read_ndjson() for the inverse; write_json() for the
array-form file; write_dataset() for the generic dispatcher.
spec <- artoo_spec(cdisc_adam_datasets, cdisc_adam_variables, codelists = cdisc_codelists)
# ---- Example 1: write a conformed dataset as NDJSON ----
#
# apply_spec() attaches the metadata; write_ndjson() streams the metadata
# line and one row per line.
adsl <- apply_spec(cdisc_adsl, spec, "ADSL", conformance = "off")
path <- tempfile(fileext = ".ndjson")
write_ndjson(adsl, path)
readLines(path, n = 2)[2]
# ---- Example 2: gzip the stream via the file extension ----
#
# A .ndjson.gz path compresses transparently; read_ndjson() inflates it.
gz <- tempfile(fileext = ".ndjson.gz")
write_ndjson(adsl, gz)
nrow(read_ndjson(gz))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.