write_datasets function

Write Package Datasets

Write Package Datasets

Exports the content of package datasets into non-proprietary, open, and well-documented standard file formats, enhancing their accessibility for future use. It supports multiple formats: CSV, JSON (requires jsonlite package), Arrow Parquet (requires arrow package), Excel XLMS (requires writexl package), GeoJSON, Shapefile, and GeoTIFF.

write_datasets( package, destdir = getwd(), formats = NULL, gzip = NULL, overwrite = TRUE, include = NULL, exclude = NULL, pretty = TRUE, quiet = FALSE )

Arguments

  • package: 'character' string. Name of a package.
  • destdir: 'character' string. Destination directory to write files, with tilde-expansion performed.
  • formats: 'character' vector. Formats for saving datasets. Choose from one or more of the following formats: txt, json, csv, xlsx, parquet, geojson, shp, and tiff. Please refer to the Details section for a description of each format. All file formats are saved to the disk by default.
  • gzip: 'character' vector. File formats that are eligible for Gzip compression. At present, it accommodates txt, json, and geojson formats exclusively.
  • overwrite: 'logical' flag. Whether to overwrite an existing file.
  • include: 'character' vector. Names(s) of datasets to include. By default, a file is created for each package dataset.
  • exclude: 'character' vector. Name(s) of datasets to exclude. By default, none are excluded.
  • pretty: 'logical' flag. Whether to add indentation, whitespace, and newlines to JSON output (default is TRUE). See prettify function for details. The tradeoff for human-readable output is a much larger file size.
  • quiet: 'logical' flag. Whether to suppress printing of debugging information.

Returns

Invisibly returns the output file path(s).

Details

Different types of datasets are written to various file formats. For instance, a dataset in the form of a data table (data.frame class) is exported to a CSV (csv), JSON (json), Parquet (parquet), and Spreadsheet (xlsx) file. A dataset representing simple features (sf or sfc class) is exported to a GeoJSON (geojson) and Shapefile (shp) file. A spatial-raster dataset (SpatRaster or PackedSpatRaster class) is exported to a GeoTIFF (tiff) file. Lastly, a coordinate reference system (crs class) is exported to a text (txt) file.

Examples

dir <- tempfile("") write_datasets( package = "inldata", destdir = dir, formats = c("txt", "csv", "json", "geojson"), include = c("crs", "dl", "inl"), pretty = FALSE, quiet = TRUE ) unlink(dir, recursive = TRUE)

Author(s)

J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center