Save a dataset

save_data(dataset, path, type = ".rds", name = NULL)

Arguments

dataset

(list) One or more datasets of the structure returned by read_data(). Name of the dataset object will become the file name if name is not used.

path

(character) Path to the directory in which dataset will be written.

type

(character) Type of file to save the dataset as. Default is ".rds" but can also be ".csv". Note: metadata and validation_issues are lost when using ".csv".

name

(character) An optional argument for setting the saved file name (for .rds) if you'd like it to be different than dataset's object name.

Value

.rds

If type = ".rds", then an .rds representation of dataset is returned.

.csv

If type = ".csv", then an set of .csv files are written to a sub-directory of path named after the data package/product ID.

Note

Subsequent calls won't overwrite files or directories

Examples

# Create directory for the data mypath <- paste0(tempdir(), "/data") dir.create(mypath) # Save as .rds save_data(ants_L1, mypath)
#> Writing ants_L1.rds to C:\Users\Colin\AppData\Local\Temp\RtmpsNoMEE/data
dir(mypath)
#> [1] "ants_L1.rds"
# Save as .rds with the name "mydata" save_data(ants_L1, mypath, name = "mydata")
#> Writing mydata.rds to C:\Users\Colin\AppData\Local\Temp\RtmpsNoMEE/data
dir(mypath)
#> [1] "ants_L1.rds" "mydata.rds"
# Save as .csv save_data(ants_L1, mypath, type = ".csv")
#> Writing edi.193.5 as .csv to C:\Users\Colin\AppData\Local\Temp\RtmpsNoMEE/data
dir(mypath)
#> [1] "ants_L1.rds" "edi.193.5" "mydata.rds"
if (FALSE) { # Save multiple datasets ids <- c("edi.193.5", "edi.303.2", "edi.290.2") datasets <- lapply(ids, read_data) save_data(datasets, mypath) dir(mypath) } # Clean up unlink(mypath, recursive = TRUE)