| Title: | Download Contact Surveys for Use in Infectious Disease Modelling |
|---|---|
| Description: | Download, cache, and manage social contact survey data from the social contact data community on Zenodo (<https://zenodo.org/communities/social_contact_data>) for use in infectious disease modelling. Provides functions to list available surveys, download survey files with automatic caching, and retrieve citations. Contact survey data describe who contacts whom in a population and are used to parameterise age-structured transmission models, for example via the 'socialmixr' package. The surveys available include those from the POLYMOD study (Mossong et al. (2008) <doi:10.1371/journal.pmed.0050074>) and other social contact data shared on Zenodo. |
| Authors: | Sebastian Funk [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-2842-3406>), Nicholas Tierney [aut] (ORCID: <https://orcid.org/0000-0003-1460-8722>), Hugo Gruson [ctb] (ORCID: <https://orcid.org/0000-0002-4094-1476>) |
| Maintainer: | Sebastian Funk <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0.9000 |
| Built: | 2026-05-11 09:04:07 UTC |
| Source: | https://github.com/epiforecasts/contactsurveys |
Returns a platform-specific directory for persistent storage of downloaded
survey files, powered by tools::R_user_dir(). You can override this by
setting the environment variable CONTACTSURVEYS_HOME.
contactsurveys_dir()contactsurveys_dir()
By default, download_survey() and list_surveys() use tempdir() so
files do not persist across R sessions. To enable persistent caching, pass
contactsurveys_dir() as the directory argument, e.g.
download_survey(survey, directory = contactsurveys_dir()).
the active contactsurveys directory.
contactsurveys_dir() ## Override with an environment variable: Sys.setenv(CONTACTSURVEYS_HOME = tempdir()) contactsurveys_dir() ## Unset Sys.unsetenv("CONTACTSURVEYS_HOME")contactsurveys_dir() ## Override with an environment variable: Sys.setenv(CONTACTSURVEYS_HOME = tempdir()) contactsurveys_dir() ## Unset Sys.unsetenv("CONTACTSURVEYS_HOME")
Delete files in contactsurveys directory
delete_contactsurveys_files(dir = contactsurveys_dir()) delete_contactsurveys_dir(dir = contactsurveys_dir())delete_contactsurveys_files(dir = contactsurveys_dir()) delete_contactsurveys_dir(dir = contactsurveys_dir())
dir |
directory to list files to delete from |
nothing, deletes files.
delete_contactsurveys_files()delete_contactsurveys_files()
For when you want to delete files associated with a given survey.
delete_survey(survey)delete_survey(survey)
survey |
Survey, as used in |
nothing, deleted files
delete_contactsurveys_dir() delete_contactsurveys_files()
peru_doi <- "https://doi.org/10.5281/zenodo.1095664" delete_survey(peru_doi)peru_doi <- "https://doi.org/10.5281/zenodo.1095664" delete_survey(peru_doi)
Downloads survey data. Uses a caching mechanism via the default
argument for directory.
download_survey( survey, directory = tempdir(), verbose = TRUE, overwrite = FALSE, timeout = 3600, rate = purrr::rate_backoff(pause_base = 5, max_times = 4) )download_survey( survey, directory = tempdir(), verbose = TRUE, overwrite = FALSE, timeout = 3600, rate = purrr::rate_backoff(pause_base = 5, max_times = 4) )
survey |
A DOI of a survey, (see |
directory |
Directory of where to save survey files. Defaults to
|
verbose |
Whether downloads should be echoed to output. Default TRUE. |
overwrite |
If files should be overwritten if they already exist. Default FALSE |
timeout |
A numeric value specifying timeout in seconds. Default 3600 seconds. |
rate |
a
purrr rate
object, to facilitate downloading if the download fails. Defaults to an
exponential backoff of 5 seconds (up to 4 attempts: 1 initial + 3 retries)
changed by specifying your own rate object, see |
a vector of filenames, where the surveys were downloaded
list_surveys() peru_survey <- download_survey("https://doi.org/10.5281/zenodo.1095664")list_surveys() peru_survey <- download_survey("https://doi.org/10.5281/zenodo.1095664")
This is a wrapper around zen4R::get_citation() with a couple of smaller
changes. Firstly, it silences output from zen4R::get_citation(), secondly
the default citation style is "apa".
get_citation( doi, style = c("bibtex", "apa", "harvard-cite-them-right", "modern-language-association", "vancouver", "chicago-fullnote-bibliography", "ieee"), verbose = TRUE )get_citation( doi, style = c("bibtex", "apa", "harvard-cite-them-right", "modern-language-association", "vancouver", "chicago-fullnote-bibliography", "ieee"), verbose = TRUE )
doi |
A string, the Zenodo DOI or concept DOI. |
style |
A string, the citation style. Default is "bibtex". Possible values are: "bibtex", "harvard-cite-them-right", "apa", "modern-language-association", "vancouver", "chicago-fullnote-bibliography", or "ieee". |
verbose |
logical. Should messages during citation fetching print to the screen? Default is TRUE. |
A character string containing the citation in the requested style.
For "bibtex" style, returns an object of class "csbib".
polymod_doi <- "https://doi.org/10.5281/zenodo.3874557" get_citation(polymod_doi)polymod_doi <- "https://doi.org/10.5281/zenodo.3874557" get_citation(polymod_doi)
Checks if a character string is a DOI
is_doi(x)is_doi(x)
x |
Character vector; the string or strings to check |
Logical; TRUE if x is a DOI, FALSE otherwise
Sebastian Funk
List all surveys available for download
list_surveys( directory = tempdir(), overwrite = FALSE, verbose = TRUE, rate = purrr::rate_backoff(pause_base = 5, max_times = 4) )list_surveys( directory = tempdir(), overwrite = FALSE, verbose = TRUE, rate = purrr::rate_backoff(pause_base = 5, max_times = 4) )
directory |
Directory to save the cached survey list. Defaults to
|
overwrite |
If files should be overwritten if they already exist. Default FALSE |
verbose |
Whether downloads should be echoed to output. Default TRUE. |
rate |
a
purrr rate
object, to facilitate downloading if the download fails. Defaults to an
exponential backoff of 5 seconds (up to 4 attempts: 1 initial + 3 retries)
changed by specifying your own rate object, see |
data.table with columns: date_added, title, creator, url
list_surveys()list_surveys()
It can be handy to see which files are available, sometimes to return to
a clean slate and delete them via the delete_contactsurveys_*() functions.
ls_contactsurveys(dir = contactsurveys_dir())ls_contactsurveys(dir = contactsurveys_dir())
dir |
Directory to list. Default is |
Character vector of file paths under dir (absolute paths).
delete_contactsurveys_files() delete_survey()
delete_contactsurveys_dir() download_survey() contactsurveys_dir()
ls_contactsurveys()ls_contactsurveys()
Print a csbib citation
## S3 method for class 'csbib' print(x, ...)## S3 method for class 'csbib' print(x, ...)
x |
A |
... |
Additional arguments passed to methods. |
Invisibly returns x.