| Title: | Access Versioned VIRION Data |
|---|---|
| Description: | This package provides an ergonomic interface for accessing the VIRION dataset (https://doi.org/10.5281/zenodo.15643003). |
| Authors: | Collin Schwantes [aut, cre] (ORCID: <https://orcid.org/0000-0002-9882-941X>) |
| Maintainer: | Collin Schwantes <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 2.0.0 |
| Built: | 2026-10-07 11:48:06 UTC |
| Source: | https://github.com/viralemergence/virionData |
This is download_deposit_version wrapped in a purr::map call.
batch_download_deposit_versions(zenodo_ids = "all", dir_path, ...)batch_download_deposit_versions(zenodo_ids = "all", dir_path, ...)
zenodo_ids |
Character. Either a vector of zenodo ids or "all" |
dir_path |
Character. Path to folder where files should be downloaded. |
... |
Other arguments passed to |
List of download locations.
## Not run: # get all deposit versions batch_download_deposit_versions(dir_path = "outputs") # get select versions batch_download_deposit_versions(zenodo_ids = c("15677137", "15643004"), dir_path = "outputs") ## End(Not run)## Not run: # get all deposit versions batch_download_deposit_versions(dir_path = "outputs") # get select versions batch_download_deposit_versions(zenodo_ids = c("15677137", "15643004"), dir_path = "outputs") ## End(Not run)
An R6 client for getting virion data and metadata.
A deposit class (R6 class)
invisibly returns self
dataframe of remote csv file.
String. Path to download location.
data.frame from readr::read_csv()
String. cleaned zenodo id
metadata in the specificed format (invisible)
List. Named list of data frames with the following fields:
name = field name
type = field type
description = characterization of the field
parent_id String. Identifier for a Zenodo deposit with multiple versions.
all_versions Character. All zenodo ids for versions of the deposit.
summary_df Data frame. A table of all zenodo ids for versions of the deposit.
latest_version String. Identifier for the latest version of the zenodo deposit.
working_version String. Identifier for the version of the zenodo deposit you are working with
working_bibtex String. Bibtex for the version of the zenodo deposit you are working with.
working_citation String. Citation for the version of the zenodo deposit you are working with.
working_files Data frame. Working files consist of key (file name) and url (url to file on zenodo)
working_json list. Metadata for the working version.
new()
Create a new deposit object, as an R6
client. This object is connected to the zenodo deposit for virion
and is the gateway for accessing different versions of the data.
deposit$new(parent_id = "15643003")
parent_idString. Identifier for a Zenodo deposit with multiple versions.
A new deposit object
\dontrun{
virion_deposit <- deposit$new()
}
set_working_version()
Set the version of the data you would like to work with. Note that the structure of Virion data may change through time.
deposit$set_working_version( zenodo_id = "latest", style = "apa", print_bibtex = TRUE, print_citation = TRUE )
zenodo_idString. A zenodo id or latest.
styleString. The citation style to be used.
print_bibtexLogical. Should the bibtex for the working version of the deposit be printed when setting the working version?
print_citationLogical. Should the citation for the working version of the deposit be printed?
\dontrun{
# set the working version to the latest version of the deposit
virion_deposit$set_working_version("latest")
# set the working versino to an arbitrary deposit
virion_deposit$get_all_versions()
virion_deposit$set_working_version("19502921")
}
load_remote_csv_file()
Load a remote csv listed in the working files field directly into the environment.
Can handle either csv or csv.gz files. This function downloads a temporary file to your machine, reads it, then returns a dataframe.
The local file cache is removed when your R session restarts.
Consider using the download_versioned_data to
save a persistent version of the virion dataset on
your machine.
deposit$load_remote_csv_file(file_key, refresh = FALSE, ...)
file_keyString. A file key as seen in the working_files field
refreshLogical. Should files be re-downloaded.
...Additional arguments to pass to readr::read_csv()
\dontrun{
## see the working files
working_files <- virion$get_working_files()
working_files$file_key
virion_data <- virion_deposit$load_remote_csv_file("virion.csv.gz")
}
download_versioned_data()
Download versioned data
Downloads all the files for a particular version of
Virion to dir/zenodo_id.
This function does not change the working version!
deposit$download_versioned_data( zenodo_id = "working", dir = "outputs", refresh = FALSE )
zenodo_idString. A zenodo id, working or latest
dirString. Storage location for files
refreshLogical. Should files be re-downloaded.
\dontrun{
# download files for the working version
virion_deposit$download_versioned_data()
# download files for the latest version
virion_deposit$download_versioned_data("latest")
# download files for some zenodo id
virion_deposit$download_versioned_data("19502921")
}
load_local_csv_file()
Load a local version of the csv.
Assumes you would like to load the file from the current working version.
If the csv file is not present, a persistent version of the file will be downloaded to your machine.
deposit$load_local_csv_file(file_key, refresh, ...)
file_keystring. Name of file from working_files
refreshlogical. Should the file be re-downloaded?
...Additional parameters to pass to readr::read_csv()
\dontrun{
virion <- deposit$new()
virion$set_working_version()
working_files <- virion$get_working_files()
working_files$file_key
virion$load_local_csv_file("virion.csv.gz")
}
check_zenodo_id()
Check the zenodo ID
Look for key words like working or latest and convert
them to integer ids OR pass the zenodo id directly
to sanitize_id()
deposit$check_zenodo_id(zenodo_id)
zenodo_idString. One of working, latest, or a zenodo id
\dontrun{
virion_deposit$check_zenodo_id("latest")
}
export_metadata()
Export metadata for a version of the deposit.
deposit$export_metadata(zenodo_id, format, verbose)
zenodo_idString. One of "latest","working", or a zenodo id
formatString. One of "json", "json-ld","csl","datacite-json","datacite-xml", "dublincore","marcxml","bibtex","geojson","dcat-ap","codemeta", "cff"
verboseLogical. Print the metadata
\dontrun{
virion_deposit$export_metadata("working")
}
get_data_dictionary()
Create a list of data dictionaries.
deposit$get_data_dictionary( file_key = "datapackage.json", dir = tempdir(), refresh )
file_keystring. Name of file from working_files
dirstring. Name of directory
refreshrefresh Logical. Should files be re-downloaded.
\dontrun{
virion <- deposit$new()
virion$set_working_version()
virion$get_data_dictionary()
}
get_parent_id()
Get a property of the object that is private
all_versions Character. All zenodo ids for versions of the deposit.
summary_df Data frame. A table of all zenodo ids for versions of the deposit.
latest_version String. Identifier for the latest version of the zenodo deposit.
working_version String. Identifier for the version of the zenodo deposit you are working with.
working_bibtex String. Bibtex for the version of the zenodo deposit you are working with.,
working_citation String. Citation for the version of the zenodo deposit you are working with.
working_files Data frame. Working files consist of key (file name) and url (url to file on zenodo)
working_json list. Metadata for the working version.
deposit$get_parent_id()
get_all_versions()
Get a property of the object that is private
deposit$get_all_versions()
get_summary_df()
Get a property of the object that is private
latest_version String. Identifier for the latest version of the zenodo deposit.
working_version String. Identifier for the version of the zenodo deposit you are working with.
working_bibtex String. Bibtex for the version of the zenodo deposit you are working with.,
working_citation String. Citation for the version of the zenodo deposit you are working with.
working_files Data frame. Working files consist of key (file name) and url (url to file on zenodo)
working_json list. Metadata for the working version.
deposit$get_summary_df()
get_latest_version()
Get a property of the object that is private
deposit$get_latest_version()
get_working_version()
Get a property of the object that is private
deposit$get_working_version()
get_working_bibtex()
Get a property of the object that is private
deposit$get_working_bibtex()
get_working_citation()
Get a property of the object that is private
deposit$get_working_citation()
get_working_files()
Get a property of the object that is private
deposit$get_working_files()
get_working_json()
Get a property of the object that is private
deposit$get_working_json()
clone()
The objects of this class are cloneable with this method.
deposit$clone(deep = FALSE)
deepWhether to make a deep clone.
## Not run: # make a client virion_deposit <- deposit$new() # methods virion_deposit$set_working_version("latest") virion_deposit$get_working_files() # load remote data directly into your session virion_data <- virion_deposit$load_remote_csv_file(file_key = "virion.csv.gz") # download remote data to disk - defaults to working version virion_deposit$download_versioned_data() ## End(Not run) ## ------------------------------------------------ ## Method `deposit$new` ## ------------------------------------------------ ## Not run: virion_deposit <- deposit$new() ## End(Not run) ## ------------------------------------------------ ## Method `deposit$set_working_version` ## ------------------------------------------------ ## Not run: # set the working version to the latest version of the deposit virion_deposit$set_working_version("latest") # set the working versino to an arbitrary deposit virion_deposit$get_all_versions() virion_deposit$set_working_version("19502921") ## End(Not run) ## ------------------------------------------------ ## Method `deposit$load_remote_csv_file` ## ------------------------------------------------ ## Not run: ## see the working files working_files <- virion$get_working_files() working_files$file_key virion_data <- virion_deposit$load_remote_csv_file("virion.csv.gz") ## End(Not run) ## ------------------------------------------------ ## Method `deposit$download_versioned_data` ## ------------------------------------------------ ## Not run: # download files for the working version virion_deposit$download_versioned_data() # download files for the latest version virion_deposit$download_versioned_data("latest") # download files for some zenodo id virion_deposit$download_versioned_data("19502921") ## End(Not run) ## ------------------------------------------------ ## Method `deposit$load_local_csv_file` ## ------------------------------------------------ ## Not run: virion <- deposit$new() virion$set_working_version() working_files <- virion$get_working_files() working_files$file_key virion$load_local_csv_file("virion.csv.gz") ## End(Not run) ## ------------------------------------------------ ## Method `deposit$check_zenodo_id` ## ------------------------------------------------ ## Not run: virion_deposit$check_zenodo_id("latest") ## End(Not run) ## ------------------------------------------------ ## Method `deposit$export_metadata` ## ------------------------------------------------ ## Not run: virion_deposit$export_metadata("working") ## End(Not run) ## ------------------------------------------------ ## Method `deposit$get_data_dictionary` ## ------------------------------------------------ ## Not run: virion <- deposit$new() virion$set_working_version() virion$get_data_dictionary() ## End(Not run)## Not run: # make a client virion_deposit <- deposit$new() # methods virion_deposit$set_working_version("latest") virion_deposit$get_working_files() # load remote data directly into your session virion_data <- virion_deposit$load_remote_csv_file(file_key = "virion.csv.gz") # download remote data to disk - defaults to working version virion_deposit$download_versioned_data() ## End(Not run) ## ------------------------------------------------ ## Method `deposit$new` ## ------------------------------------------------ ## Not run: virion_deposit <- deposit$new() ## End(Not run) ## ------------------------------------------------ ## Method `deposit$set_working_version` ## ------------------------------------------------ ## Not run: # set the working version to the latest version of the deposit virion_deposit$set_working_version("latest") # set the working versino to an arbitrary deposit virion_deposit$get_all_versions() virion_deposit$set_working_version("19502921") ## End(Not run) ## ------------------------------------------------ ## Method `deposit$load_remote_csv_file` ## ------------------------------------------------ ## Not run: ## see the working files working_files <- virion$get_working_files() working_files$file_key virion_data <- virion_deposit$load_remote_csv_file("virion.csv.gz") ## End(Not run) ## ------------------------------------------------ ## Method `deposit$download_versioned_data` ## ------------------------------------------------ ## Not run: # download files for the working version virion_deposit$download_versioned_data() # download files for the latest version virion_deposit$download_versioned_data("latest") # download files for some zenodo id virion_deposit$download_versioned_data("19502921") ## End(Not run) ## ------------------------------------------------ ## Method `deposit$load_local_csv_file` ## ------------------------------------------------ ## Not run: virion <- deposit$new() virion$set_working_version() working_files <- virion$get_working_files() working_files$file_key virion$load_local_csv_file("virion.csv.gz") ## End(Not run) ## ------------------------------------------------ ## Method `deposit$check_zenodo_id` ## ------------------------------------------------ ## Not run: virion_deposit$check_zenodo_id("latest") ## End(Not run) ## ------------------------------------------------ ## Method `deposit$export_metadata` ## ------------------------------------------------ ## Not run: virion_deposit$export_metadata("working") ## End(Not run) ## ------------------------------------------------ ## Method `deposit$get_data_dictionary` ## ------------------------------------------------ ## Not run: virion <- deposit$new() virion$set_working_version() virion$get_data_dictionary() ## End(Not run)
Simple summary data frame for the deposit
deposit_summary()deposit_summary()
data frame. Simplified deposit metadata with the following fields:
id = zenodo id
latest_version = True or False indicating if that record is the latest version of the dataset.
publication_date = YMD the item was published to zenodo
doi_url = digital object identifier for that version of the record.
deposit_summary()deposit_summary()
Downloads and extracts some version of the deposit.
download_deposit_version( zenodo_id, deposit_versions = list_deposit_versions(), dir_path, datapackage_only = FALSE )download_deposit_version( zenodo_id, deposit_versions = list_deposit_versions(), dir_path, datapackage_only = FALSE )
zenodo_id |
String. ID for a Zenodo deposit. Should correspond to the version of a deposit. |
deposit_versions |
data frame. Output from |
dir_path |
String. Path to directory where the files should be downloaded e.g. "inst/extdata/wdds_archive" note no trailing slash on the path. |
datapackage_only |
Logical. Download only the datapackage.json file |
String. Path to downloaded version.
Downloads a file or re-downloads a file to refresh the cached files.
download_refresh(file_url, local, refresh)download_refresh(file_url, local, refresh)
file_url |
String. URL for file you'd like to download |
local |
String. A character string with the name where the downloaded file is saved. Tilde-expansion is performed. |
refresh |
Logical. Should saved files be refreshed. |
String. Local File path
Apparently a known issue in R6 as the class is not created until install.
dummy_imports()dummy_imports()
Character string explaining why this function exists.
Bibtex specific wrapper for export_deposit_metadata
export_deposit_bibtex(zenodo_id = the$working_version, verbose = TRUE)export_deposit_bibtex(zenodo_id = the$working_version, verbose = TRUE)
zenodo_id |
String. ID for a Zenodo deposit. Should correspond to the version of a deposit. |
verbose |
Logical. Print the formatted metadata? |
Character. bibtex formatted entry
## Not run: export_deposit_bibtex(zenodo_id = "15692263" ) |> writeLines(con = "outputs/citation.bib") ## End(Not run)## Not run: export_deposit_bibtex(zenodo_id = "15692263" ) |> writeLines(con = "outputs/citation.bib") ## End(Not run)
Export Deposit Metadata in various formats
export_deposit_metadata( zenodo_id = the$working_version, format, verbose = TRUE )export_deposit_metadata( zenodo_id = the$working_version, format, verbose = TRUE )
zenodo_id |
String. ID for a Zenodo deposit. Should correspond to the version of a deposit. |
format |
String. File format for export. One of "json", "json-ld","csl","datacite-json","datacite-xml", "dublincore","marcxml","bibtex","geojson","dcat-ap","codemeta", or "cff" |
verbose |
Logical. Print the formatted metadata? |
Character. Returns text in selected format.
## Not run: export_deposit_metadata(zenodo_id = "15692263","json-ld" ) |> writeLines(con = "outputs/citation.jsonld") ## End(Not run)## Not run: export_deposit_metadata(zenodo_id = "15692263","json-ld" ) |> writeLines(con = "outputs/citation.jsonld") ## End(Not run)
Recursively traverse a deposit link to get all versions of a deposit.
get_all_versions(url)get_all_versions(url)
url |
Character. URL for a version of the deposit. |
Data.frame. Metadata for all deposit version
## Not run: self_link <- "https://zenodo.org/api/records/21232661/versions?page=1&size=25&sort=version" get_all_versions(self_link) ## End(Not run)## Not run: self_link <- "https://zenodo.org/api/records/21232661/versions?page=1&size=25&sort=version" get_all_versions(self_link) ## End(Not run)
Creates a list of data frames that constitutes the data dictionary.
get_data_dictionary(datapackage_json)get_data_dictionary(datapackage_json)
datapackage_json |
Character. Path to datapackage.json file |
List. Named list of data frames with the following fields:
name = field name
type = field type
description = characterization of the field
## Not run: get_data_dictionary(datapackage_json = "data/1235600/datapackage.json") ## End(Not run)## Not run: get_data_dictionary(datapackage_json = "data/1235600/datapackage.json") ## End(Not run)
Get the dictionary for a single resource
get_individual_dictionary(x)get_individual_dictionary(x)
x |
List. Resource object from the data package. |
dataframe with three fields.
jsonlite::fromJSON() wrapped in rlang::try_fetch() to make calls
smoother.
get_json(url)get_json(url)
url |
String. A url fed to |
List. JSON as a list
## Not run: get_json("https://www.example.com/example.json") ## End(Not run)## Not run: get_json("https://www.example.com/example.json") ## End(Not run)
Get the name of a resource
get_resource_name(x)get_resource_name(x)
x |
data frame with name field |
character. Name of resources
Get Version Citation
get_version_citation( zenodo_id = the$working_version, style = c("havard-cite-them-right", "apa", "modern-language-association", "vancouver", "chicago-fullnote-bibliography", "ieee"), verbose = TRUE )get_version_citation( zenodo_id = the$working_version, style = c("havard-cite-them-right", "apa", "modern-language-association", "vancouver", "chicago-fullnote-bibliography", "ieee"), verbose = TRUE )
zenodo_id |
String. ID for a Zenodo deposit. Should correspond to the version of a deposit. |
style |
Character. One of "havard-cite-them-right", "apa", "modern-language-association", "vancouver", "chicago-fullnote-bibliography", or "ieee" |
verbose |
Logical. Print the citation? |
Character. Text for a citation
## Not run: get_version_citation(zenodo_id = "15692263", style = "apa") ## End(Not run)## Not run: get_version_citation(zenodo_id = "15692263", style = "apa") ## End(Not run)
This is a convenience function that downloads a specific version of the data and returns attribution information.
get_versioned_data( version = "latest", style = "apa", dir_path, refresh_deposits_versions = TRUE, verbose = TRUE, ... )get_versioned_data( version = "latest", style = "apa", dir_path, refresh_deposits_versions = TRUE, verbose = TRUE, ... )
version |
Character. identifier for a version e.g. "15643003" or "latest" |
style |
Charater. Character. One of "havard-cite-them-right", "apa", "modern-language-association", "vancouver", "chicago-fullnote-bibliography", or "ieee" |
dir_path |
Character. Path to folder where files should be downloaded. |
refresh_deposits_versions |
Logical. Should the function check for new versions of the deposit? |
verbose |
Logical. Include print statements? |
... |
Additional arguments to pass to |
If you would like to download a bibtex entry use export_deposit_bibtex. For
other metadata types (CSL, CFF, JSON-LD, etcetera) use export_deposit_metadata.
Character. path to versioned data.
This function gets the metadata for all the versions of a deposit associated
with a parent id. The parent id is used to identify a set of works that are
different versions of the same work. The parent id is provided by the
Zenodo API. To find the parent ID, download a JSON representation of the
deposit (export to json on the webpage or use export_deposit_metadata),
there will be an attribute called parent that looks like
"https://zenodo.org/api/records/15020049".
The 8 digit string at the end of the url is the parent id.
list_deposit_versions(parent_id = "15643003")list_deposit_versions(parent_id = "15643003")
parent_id |
String. Identifier for a Zenodo deposit with multiple versions. |
This function also sets package variables
Data frame. Invisible. The data frame contains the Zenodo id for each version of the deposit, as well as the version name, and logical field called latest that indicates if this is the latest version.
Appends a zenodo id to the zenodo api url.
make_url(base_url = "https://zenodo.org/api/records/%s", id)make_url(base_url = "https://zenodo.org/api/records/%s", id)
base_url |
string. url for zenodo api |
id |
string. zenodo id. |
String. URL for zenodo api.
make_url(id = "1235600")make_url(id = "1235600")
Remove any white space and check that it conforms to the zenodo id pattern.
sanitize_id(zenodo_id)sanitize_id(zenodo_id)
zenodo_id |
String. A zenodo id. |
String. A cleaned zenodo id.
sanitize_id(" 2948598")sanitize_id(" 2948598")
Checks that version ids are properly formatted. IDs should either be integers ("15643003") OR "latest"
sanitize_version(version)sanitize_version(version)
version |
Character. Version identifier. |
Character. Version identifier from Zenodo.
sanitize_version("latest") sanitize_version(" 15643003")sanitize_version("latest") sanitize_version(" 15643003")