Writes x to file as CSV or Parquet, and returns a Croissant object
that describes it: one FileObject with the file's size and SHA-256
checksum, one RecordSet, and one Field per column, whose data type
follows the column class: integer to sc:Integer, double to sc:Float,
logical to sc:Boolean, Date to sc:Date, POSIXct to sc:DateTime, and
character and factor to sc:Text. Write the metadata with
write_croissant() into the directory of file, where content_url
resolves.
Arguments
- x
data.frame, data.table, or tibble: The data.
- file
Character: Path of the data file to write.
- name
Character: Name of the dataset.
- format
Character {"csv", "parquet"}: File format.
"parquet"requires the 'arrow' package.- record_set
Character:
@idof the record set.- content_url
Character:
contentUrlof the file, relative to the metadata document.- version
Character {"1.0", "1.1"}: Croissant version.
- ...
Further properties of the
Croissantobject, such asdescription,license,cite_as,creator, ordate_published.
Details
A factor is written as its labels and reads back as character. In CSV, a
missing value is written as an empty field and an empty string as "",
and they read back as NA and "". Parquet keeps every column type.
Examples
dir <- tempfile()
dir.create(dir)
x <- croissant_from_data(
iris,
file.path(dir, "iris.csv"),
name = "iris",
license = "CC0-1.0"
)
x#> <Croissant>
#> name: iris
#> version: Croissant 1.1
#> distribution: 1 FileObject
#> record sets: 1
#> default: 5 fieldswrite_croissant(x, file.path(dir, "metadata.json"))
head(read_record_set(file.path(dir, "metadata.json"), "default"))#> default/Sepal.Length default/Sepal.Width default/Petal.Length
#> <num> <num> <num>
#> 1: 5.1 3.5 1.4
#> 2: 4.9 3.0 1.4
#> 3: 4.7 3.2 1.3
#> 4: 4.6 3.1 1.5
#> 5: 5.0 3.6 1.4
#> 6: 5.4 3.9 1.7
#> default/Petal.Width default/Species
#> <num> <char>
#> 1: 0.2 setosa
#> 2: 0.2 setosa
#> 3: 0.2 setosa
#> 4: 0.2 setosa
#> 5: 0.2 setosa
#> 6: 0.4 setosa