write_data: Write a data set to a file

View source: R/io.R

write_dataR Documentation

Write a data set to a file

Description

write_data() writes a data frame to any format listed by supported_formats(). The format is inferred from the file extension unless format is given; text formats are compressed when the file name ends in .gz, .bz2 or .xz.

HDF5 files are written with one dataset per column inside a group (dataset, default "data"), with attributes that record column order, factor levels, Date/POSIXct classes, time zones and missing strings, so that read_data() restores the original column types.

Date-times (POSIXct) keep their instant in every format. Text formats (CSV, TSV, JSON, NDJSON) store them as ISO 8601 strings in UTC; Excel, SPSS, Stata and SAS files, which store clock time without a time zone, receive the UTC clock time; Parquet, Feather, fst and HDF5 store the instant together with the time zone. Pass the original data as template to read_data() to restore the original time zone.

Usage

write_data(
  x,
  path,
  format = NULL,
  overwrite = TRUE,
  object = "data",
  dataset = "data",
  ...
)

Arguments

x

A data frame (matrices are converted).

path

Output file path.

format

Optional format name or extension.

overwrite

Overwrite an existing file?

object

For rdata: name under which the object is saved.

dataset

For hdf5: name of the group to write.

...

Further arguments passed to the backend writer.

Value

The path, invisibly.

See Also

read_data(), generate_to_file()

Examples

f <- tempfile(fileext = ".tsv.gz")
write_data(mtcars, f)
head(read_data(f))

SynthesizerPlus documentation built on Oct. 16, 2026, 5:10 p.m.