Skip to contents

Writes a Data Package and its related Data Resources to disk as a datapackage.json and CSV files. Already existing CSV files of the same name will not be overwritten. The function can also be used to download a Data Package in its entirety. The Data Resources are handled as follows:

  • Resource path has at least one local path (e.g. deployments.csv): CSV files are copied or downloaded to directory and path points to new location of file(s).

  • Resource path has only URL(s): resource stays as is.

  • Resource has inline data originally: resource stays as is.

  • Resource has inline data as result of adding data with add_resource(): data are written to a CSV file using readr::write_csv(), path points to location of file, data property is removed. Use compress = TRUE to gzip those CSV files.

Usage

write_package(package, directory = ".", compress = FALSE)

Arguments

package

List describing a Data Package, created with read_package() or create_package().

directory

Path to local directory to write files to.

compress

If TRUE, data of added resources will be gzip compressed before being written to disk (e.g. deployments.csv.gz).

Value

package as written to file (invisibly).

Examples

# Load the example Data Package from disk
package <- read_package(
  system.file("extdata", "datapackage.json", package = "frictionless")
)
#> Please make sure you have the right to access data from this Data Package for your intended use.
#> Follow applicable norms or requirements to credit the dataset and its authors.

# List resources
resources(package)
#> [1] "deployments"  "observations" "media"       

# Write the (unchanged) Data Package to disk
write_package(package, directory = "my_directory")

# Check files
list.files("my_directory")
#> [1] "datapackage.json" "deployments.csv" 

# No files written for the "observations" resource, since those are all URLs.
# No files written for the "media" resource, since it has inline data.

# Clean up (don't do this if you want to keep your files)
unlink("my_directory", recursive = TRUE)