write_datasets {inldata} | R Documentation |
Write Package Datasets
Description
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.
Usage
write_datasets(
package,
destdir = getwd(),
formats = NULL,
gzip = NULL,
overwrite = TRUE,
include = NULL,
exclude = NULL,
pretty = TRUE,
full_names = 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:
|
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 |
full_names |
'logical' flag. Whether the full paths of the files are returned (default). |
quiet |
'logical' flag. Whether to suppress printing of debugging information. |
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.
Value
Invisibly returns the output file path(s).
Author(s)
J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center
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)