read_ndjson_file {yyjsonr}R Documentation

Parse an NDJSON file to a data.frame or list

Description

If reading as data.frame, each row of NDJSON becomes a row in the data.frame. If reading as a list, then each row becomes an element in the list.

Usage

read_ndjson_file(
  filename,
  type = c("df", "list"),
  nread = -1,
  nskip = 0,
  nprobe = 100,
  opts = list(),
  ...
)

Arguments

filename

Path to file containing NDJSON data. May e a vanilla text file or a gzipped file

type

The type of R object the JSON should be parsed into. Valid values are 'df' or 'list'. Default: 'df' (data.frame)

nread

Number of records to read. Default: -1 (reads all JSON strings)

nskip

Number of records to skip before starting to read. Default: 0 (skip no data)

nprobe

Number of lines to read to determine types for data.frame columns. Default: 100. Use -1 to probe entire file.

opts

Named list of options for parsing. Usually created by opts_read_json()

...

Other named options can be used to override any options in opts. The valid named options are identical to arguments to opts_read_json()

Details

If parsing NDJSON to a data.frame it is usually better if the json objects are consistent from line-to-line. Type inference for the data.frame is done during initialisation by reading through nprobe lines. Warning: if there is a type-mismatch further into the file than it is probed, then you will get missing values in the data.frame, or JSON values not captured in the R data.

No flattening of the namespace is done i.e. nested object remain nested.

Value

NDJSON data read into R as list or data.frame depending on 'type' argument

See Also

Other JSON Parsers: read_json_conn(), read_json_file(), read_json_raw(), read_json_str(), read_ndjson_str()

Examples

tmp <- tempfile()
write_ndjson_file(head(mtcars), tmp)
read_ndjson_file(tmp)


[Package yyjsonr version 0.1.20 Index]