View source: R/write_datasets.R
| write_datasets | R Documentation |
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
)
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:
|
gzip |
'character' vector.
File |
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 |
quiet |
'logical' flag. Whether to suppress printing of debugging information. |
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.
Invisibly returns the output file path(s).
J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.