Skip to content

Write to NDJSON file

Description

Write to NDJSON file

Usage

<DataFrame>$write_ndjson(file)

Arguments

file File path to which the result should be written.

Value

Invisibly returns the input DataFrame.

Examples

library("polars")

dat = as_polars_df(head(mtcars))

destination = tempfile()
dat$select(pl$col("drat", "mpg"))$write_ndjson(destination)

pl$read_ndjson(destination)
#> shape: (6, 2)
#> ┌──────┬──────┐
#> │ drat ┆ mpg  │
#> │ ---  ┆ ---  │
#> │ f64  ┆ f64  │
#> ╞══════╪══════╡
#> │ 3.9  ┆ 21.0 │
#> │ 3.9  ┆ 21.0 │
#> │ 3.85 ┆ 22.8 │
#> │ 3.08 ┆ 21.4 │
#> │ 3.15 ┆ 18.7 │
#> │ 2.76 ┆ 18.1 │
#> └──────┴──────┘