Title: | Download Data from the 'Open Case Studies' Repository |
Version: | 1.0.2 |
Description: | Provides functions to access and download data from the 'Open Case Studies' https://www.opencasestudies.org/ repositories on 'GitHub' https://github.com/opencasestudies. Different functions enable users to grab the data they need at different sections in the case study, as well as download the whole case study repository. All the user needs to do is input the name of the case study being worked on. The package relies on the httr::GET() function to access files through the 'GitHub' API. The functions usethis::use_zip() and usethis::create_from_github() are used to clone and/or download the case study repositories. To cite an individual case study, please see the respective 'README' file at https://github.com/opencasestudies/. https://github.com/opencasestudies/ocs-bp-rural-and-urban-obesity https://github.com/opencasestudies/ocs-bp-air-pollution https://github.com/opencasestudies/ocs-bp-vaping-case-study https://github.com/opencasestudies/ocs-bp-opioid-rural-urban https://github.com/opencasestudies/ocs-bp-RTC-wrangling https://github.com/opencasestudies/ocs-bp-RTC-analysis https://github.com/opencasestudies/ocs-bp-youth-disconnection https://github.com/opencasestudies/ocs-bp-youth-mental-health https://github.com/opencasestudies/ocs-bp-school-shootings-dashboard https://github.com/opencasestudies/ocs-bp-co2-emissions https://github.com/opencasestudies/ocs-bp-diet. |
Imports: | usethis (≥ 2.0.0), purrr (≥ 0.3.0), httr (≥ 1.4.0) |
Depends: | R (≥ 3.5.0) |
Suggests: | testthat (≥ 3.0.0), covr, knitr, rmarkdown |
VignetteBuilder: | knitr |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
RoxygenNote: | 7.1.1 |
URL: | https://github.com/opencasestudies/OCSdata, https://doi.org/10.5281/zenodo.5214347, https://www.opencasestudies.org/ |
BugReports: | https://github.com/opencasestudies/OCSdata/issues |
Config/testthat/edition: | 3 |
NeedsCompilation: | no |
Packaged: | 2021-08-18 21:21:17 UTC; michael |
Author: | Michael Breshock [aut],
Carrie Wright |
Maintainer: | Carrie Wright <cwrigh60@jhu.edu> |
Repository: | CRAN |
Date/Publication: | 2021-08-20 06:30:02 UTC |
OCSdata: A package for downloading data from the 'Open Case Studies' repository
Description
Provides functions to access and download data from the 'Open Case Studies' repository on GitHub. Different functions enable users to grab the data they need at different sections in the case study, as well as download the whole case study repository. All the user needs to do is input the name of the case study being worked on. The package relies on the httr::GET() function to access files through the GitHub API. The functions usethis::use_zip() and usethis::create_from_github() are used to clone and/or download the case study repositories.
OCSdata functions
raw_data: downloads the data files needed to work on the data import section
simpler_import_data: downloads the raw data files in an import friendly format; usually only available when the original raw files are in an uncommon format
extra_data: downloads any extra data files that are not used in the case study
imported_data: downloads the data files used in the data wrangling and exploration sections, use this function when skipping the data import section
wrangled_data: downloads the data files used in the data analysis and visualization sections, use this function when skipping the data wrangling section.
clone_ocs: clones the case study repository with git, needs a registered personal access token (PAT)
zip_ocs: downloads the case study repository as a zip file and unzips it to a local directory
Clone Case Study Repository
Description
Clone the specified case study repository and save it as a new R project in a local directory. Need to have a personal access token (PAT) registered to work.
Usage
clone_ocs(casestudy, outpath = NULL, fork_repo = NA)
Arguments
casestudy |
character string, name of the case study to clone repository from. The input name should follow the same naming scheme as the repository on GitHub: ocs-bp-rural-and-urban-obesity ocs-bp-air-pollution ocs-bp-vaping-case-study ocs-bp-opioid-rural-urban ocs-bp-RTC-wrangling ocs-bp-RTC-analysis ocs-bp-youth-disconnection ocs-bp-youth-mental-health ocs-bp-school-shootings-dashboard ocs-bp-co2-emissions ocs-bp-diet |
outpath |
character string, path to the directory where the downloaded repository folder should be saved to. |
fork_repo |
logical, FALSE will clone the repo, while TRUE will fork the repo and then clone the fork. Default is NA, which will check if you are allowed to push to the repository or not. If you can, the repo will be cloned. If you cannot push, the repo will be forked and cloned. |
Details
This function clones the specified OCS case study repository from GitHub and saves it as a new R project in a new folder in the specified directory. This makes it so the case study repository, including all of the code, data, and document files, are cloned with git and downloaded in a single function. Need to have a personal access token (PAT) to work. Wrapper for the create_from_github function from usethis.
Value
If download is successful, the path to the downloaded data folder is printed and the logical value TRUE is returned. Otherwise the appropriate error message is printed.
Examples
## Not run:
tmp = tempfile()
dir.create(tmp)
clone_ocs("ocs-bp-co2-emissions", outpath = tmp)
## End(Not run)
Internal Function
Description
This is not to be used directly by the users.
Usage
clone_ocs_repo(casestudy, outpath = NULL, fork_repo = NA)
Download Open Case Study Extra Data
Description
Download the specified case study extra data to use as you wish.
Usage
extra_data(casestudy, outpath = NULL)
Arguments
casestudy |
character string, name of the case study to pull data from. The input name should follow the same naming scheme as the repository on GitHub: ocs-bp-opioid-rural-urban ocs-bp-RTC-wrangling ocs-bp-co2-emissions |
outpath |
character string, path to the directory where the downloaded data folder should be saved to. |
Details
This function downloads the Open Case Study extra data from GitHub and saves it in a new 'OCS_data/data/extra/' folder in the specified directory. This makes it so all the extra data are easily available in a local folder for your use.
Value
If download is successful, the path to the downloaded data folder is printed and the logical value TRUE is returned. Otherwise the appropriate error message is printed.
Examples
tmp = tempfile()
dir.create(tmp)
extra_data('ocs-bp-opioid-rural-urban', outpath = tmp)
Download Open Case Study Imported Data
Description
Download the specified case study imported data to use as you follow along the case study.
Usage
imported_data(casestudy, outpath = NULL)
Arguments
casestudy |
character string, name of the case study to pull data from. The input name should follow the same naming scheme as the repository on GitHub: ocs-bp-rural-and-urban-obesity ocs-bp-air-pollution ocs-bp-vaping-case-study ocs-bp-opioid-rural-urban ocs-bp-RTC-wrangling ocs-bp-RTC-analysis ocs-bp-youth-disconnection ocs-bp-youth-mental-health ocs-bp-school-shootings-dashboard ocs-bp-co2-emissions ocs-bp-diet |
outpath |
character string, path to the directory where the downloaded data folder should be saved to. |
Details
This function downloads the Open Case Study imported data from GitHub and saves it in a new 'OCSdata/data/imported/' folder in the specified directory. This makes it so all the imported data are easily available in a local folder.
Value
If download is successful, the path to the downloaded data folder is printed and the logical value TRUE is returned. Otherwise the appropriate error message is printed.
Examples
tmp = tempfile()
dir.create(tmp)
imported_data('ocs-bp-opioid-rural-urban', outpath = tmp)
Internal Function
Description
This is not to be used directly by the users.
Usage
load_extra_data(casestudy, outpath = NULL)
Internal Function
Description
This is not to be used directly by the users.
Usage
load_imported_data(casestudy)
Internal Function
Description
This is not to be used directly by the users.
Usage
load_raw_data(casestudy, outpath = NULL)
Internal Function
Description
This is not to be used directly by the users.
Usage
load_repo(casestudy, outpath = NULL)
Internal Function
Description
This is not to be used directly by the users.
Usage
load_simpler_import(casestudy, outpath = NULL)
Internal Function
Description
This is not to be used directly by the users.
Usage
load_wrangled_data(casestudy, outpath = NULL)
Download Open Case Study Raw Data
Description
Download the specified case study raw data to use as you follow along the case study.
Usage
raw_data(casestudy, outpath = NULL)
Arguments
casestudy |
character string, name of the case study to pull data from. The input name should follow the same naming scheme as the repository on GitHub: ocs-bp-rural-and-urban-obesity ocs-bp-air-pollution ocs-bp-vaping-case-study ocs-bp-opioid-rural-urban ocs-bp-RTC-wrangling ocs-bp-RTC-analysis ocs-bp-youth-disconnection ocs-bp-youth-mental-health ocs-bp-school-shootings-dashboard ocs-bp-co2-emissions ocs-bp-diet |
outpath |
character string, path to the directory where the downloaded data folder should be saved. |
Details
This function downloads the Open Case Study raw data from GitHub and saves it in a new 'OCS_data/data/raw/' folder in the specified directory. This makes it so all the raw data are easily available in a local folder to be processed and wrangled.
Value
If download is successful, the path to the downloaded data folder is printed and the logical value TRUE is returned. Otherwise the appropriate error message is printed.
Examples
tmp = tempfile()
dir.create(tmp)
raw_data('ocs-bp-opioid-rural-urban', outpath = tmp)
Download Open Case Study Simpler Import Data
Description
Download the specified case study simpler import data to use as you follow along the case study.
Usage
simpler_import_data(casestudy, outpath = NULL)
Arguments
casestudy |
character string, name of the case study to pull data from. The input name should follow the same naming scheme as the repository on GitHub: ocs-bp-vaping-case-study ocs-bp-opioid-rural-urban ocs-bp-youth-disconnection |
outpath |
character string, path to the directory where the downloaded data folder should be saved to. |
Details
This function downloads the Open Case Study simpler import data from GitHub and saves it in a new 'OCS_data/data/simpler_import/' folder in the specified directory. This makes it so all the simpler import data are easily available in a local folder to be processed and wrangled.
Value
If download is successful, the path to the downloaded data folder is printed and the logical value TRUE is returned. Otherwise the appropriate error message is printed.
Examples
tmp = tempfile()
dir.create(tmp)
simpler_import_data('ocs-bp-opioid-rural-urban', outpath = tmp)
Download Open Case Study Wrangled Data - CSVs
Description
Download the specified case study wrangled data to use as you follow along the case study.
Usage
wrangled_csv(casestudy, outpath = NULL)
Arguments
casestudy |
character string, name of the case study to pull data from. The input name should follow the same naming scheme as the repository on GitHub: ocs-bp-rural-and-urban-obesity ocs-bp-air-pollution ocs-bp-vaping-case-study ocs-bp-opioid-rural-urban ocs-bp-RTC-wrangling ocs-bp-RTC-analysis ocs-bp-youth-disconnection ocs-bp-youth-mental-health ocs-bp-school-shootings-dashboard ocs-bp-co2-emissions ocs-bp-diet |
outpath |
character string, path to the directory where the downloaded data folder should be saved to. |
Details
This function downloads the Open Case Study wrangled data from GitHub and saves it in a new 'OCSdata/data/wrangled/' folder in the specified directory. This makes it so all the wrangled data are easily available in a local folder. The data will be in .csv format.
Value
If download is successful, the path to the downloaded data folder is printed and the logical value TRUE is returned. Otherwise the appropriate error message is printed.
Examples
tmp = tempfile()
dir.create(tmp)
wrangled_csv('ocs-bp-opioid-rural-urban', outpath = tmp)
Download Open Case Study Wrangled Data - RDAs
Description
Download the specified case study wrangled data to use as you follow along the case study.
Usage
wrangled_rda(casestudy, outpath = NULL)
Arguments
casestudy |
character string, name of the case study to pull data from. The input name should follow the same naming scheme as the repository on GitHub: ocs-bp-rural-and-urban-obesity ocs-bp-air-pollution ocs-bp-vaping-case-study ocs-bp-opioid-rural-urban ocs-bp-RTC-wrangling ocs-bp-RTC-analysis ocs-bp-youth-disconnection ocs-bp-youth-mental-health ocs-bp-school-shootings-dashboard ocs-bp-co2-emissions ocs-bp-diet |
outpath |
character string, path to the directory where the downloaded data folder should be saved to. |
Details
This function downloads the Open Case Study wrangled data from GitHub and saves it in a new 'OCSdata/data/wrangled/' folder in the specified directory. This makes it so all the wrangled data are easily available in a local folder. The data will be in .rda format.
Value
If download is successful, the path to the downloaded data folder is printed and the logical value TRUE is returned. Otherwise the appropriate error message is printed.
Examples
tmp = tempfile()
dir.create(tmp)
wrangled_rda('ocs-bp-opioid-rural-urban', outpath = tmp)
Download Case Study Repository Zip File
Description
Download the specified case study repository zip file and unzip it to a local directory.
Usage
zip_ocs(casestudy, outpath = NULL)
Arguments
casestudy |
character string, name of the case study to download zip file from. The input name should follow the same naming scheme as the repository on GitHub: ocs-bp-rural-and-urban-obesity ocs-bp-air-pollution ocs-bp-vaping-case-study ocs-bp-opioid-rural-urban ocs-bp-RTC-wrangling ocs-bp-RTC-analysis ocs-bp-youth-disconnection ocs-bp-youth-mental-health ocs-bp-school-shootings-dashboard ocs-bp-co2-emissions ocs-bp-diet |
outpath |
character string, path to the directory where the downloaded data folder should be saved. |
Details
This function downloads the specified OCS case study repository from GitHub as a zip file. The function unzips the folder and saves it as a new R project in a local directory. This makes it so the case study repository, including all of the code, data, and document files, are downloaded with a single function. Wrapper for the use_zip function from usethis.
Value
If download is successful, the path to the downloaded data folder is printed and the logical value TRUE is returned. Otherwise the appropriate error message is printed.
Examples
tmp = tempfile()
dir.create(tmp)
zip_ocs('ocs-bp-co2-emissions', outpath = tmp)