| read_ndjson | R Documentation |
Read a newline-delimited CDISC Dataset-JSON v1.1 (.ndjson) file back to
a data frame, restoring the full artoo_meta from its metadata line and
realizing SAS date/datetime/time variables to R Date / POSIXct /
hms::hms. Rows are parsed in bounded slabs, and n_max stops the
line loop early, so a partial read of a huge file never parses the tail.
A thin wrapper over read_dataset() with format = "ndjson".
read_ndjson(path, col_select = NULL, n_max = Inf, encoding = NULL)
path |
Source |
col_select |
Variables to read. Note: an unknown name is a |
n_max |
Maximum records to read. |
encoding |
Source charset of the file bytes. |
A <data.frame> carrying artoo_meta (read it with
get_meta()).
write_ndjson() for the inverse; read_json() for the
array-form file; read_dataset() for the generic dispatcher.
spec <- artoo_spec(cdisc_adam_datasets, cdisc_adam_variables, codelists = cdisc_codelists)
# ---- Example 1: round-trip a conformed dataset through NDJSON ----
#
# The variable labels, types, and keys survive the round-trip.
adsl <- apply_spec(cdisc_adsl, spec, "ADSL", conformance = "off")
path <- tempfile(fileext = ".ndjson")
write_ndjson(adsl, path)
back <- read_ndjson(path)
identical(get_meta(back)@columns, get_meta(adsl)@columns)
# ---- Example 2: a bounded partial read of the first rows ----
#
# n_max stops the line loop as soon as enough rows are in.
head_rows <- read_ndjson(path, n_max = 5)
get_meta(head_rows)@dataset$records
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.