Learn R Programming

OCSdata

Download Data from Open Case Studies (OCS)

OCSdata is an R package to help you access and download case study data files hosted on the OCS GitHub. The package provides several different functions to 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 use the package is the name of the case study repository and a file path to the directory where the data should be saved. The package relies on the GET() function from httr to access files through the GitHub API. The functions use_zip() and create_from_github() from usethis are used to clone and/or download the case study repositories.

Installation

Download the current release version from CRAN:

install.packages("OCSdata")

Download the current development version from GitHub:

# install.packages("devtools")
devtools::install_github("opencasestudies/OCSdata")

Examples

These examples download the data files to temporary directories to avoid overwriting local files. If you'd like to save the files elsewhere, specify the file path to the desired download location in the outpath argument. Or, leave the argument blank to interactively specify a directory with the R console.

library(OCSdata)

# Starting at data import section:
raw_data("ocs-bp-opioid-rural-urban", outpath = tempdir())

# for raw data in file formats that are easier to import, run:
simpler_import_data("ocs-bp-opioid-rural-urban", outpath = tempdir())

# Starting at data exploration/wrangling sections: 
imported_data("ocs-bp-opioid-rural-urban", outpath = tempdir())

# Starting at data visualization/analysis sections:
# for files in CSV format: 
wrangled_csv("ocs-bp-opioid-rural-urban", outpath = tempdir())

# for files in RDA format: 
wrangled_rda("ocs-bp-opioid-rural-urban", outpath = tempdir())

# Looking for more data on this topic: 
extra_data("ocs-bp-opioid-rural-urban", outpath = tempdir())

# Download repository in a zip file: 
zip_ocs("ocs-bp-opioid-rural-urban", outpath = tempdir())

# Clone the case study GitHub repository (requires registered PAT): 
clone_ocs("ocs-bp-opioid-rural-urban", outpath = tempdir(), fork_repo = TRUE)

# Setting fork_repo = TRUE will fork the repo first and then clone the fork, 
# while FALSE will clone the repo directly from the Open Case Studies GitHub. 
# The default is fork_repo = NA, which will fork or clone based on your repository 
# permissions. This function requires your personal GitHub PAT to be registered in RStudio. 

Note: The default argument for outpath will trigger an interactive session where the user confirms the download location.

These examples use the Opioids in United States case study, but you can use these functions with any of our case studies. Make sure to use the Case Study ID for the casestudy argument. See below to find your case study's ID:

Case Study NameCase Study ID
Exploring global patterns of obesity across rural and urban regionsocs-bp-rural-and-urban-obesity
Predicting Annual Air Pollutionocs-bp-air-pollution
Vaping Behaviors in American Youthocs-bp-vaping-case-study
Opioids in United Statesocs-bp-opioid-rural-urban
Influence of Multicollinearity on Measured Impact of Right-to-Carry Gun Laws Part 1ocs-bp-RTC-wrangling
Influence of Multicollinearity on Measured Impact of Right-to-Carry Gun Laws Part 2ocs-bp-RTC-analysis
Disparities in Youth Disconnectionocs-bp-youth-disconnection
Mental Health of American Youthocs-bp-youth-mental-health
School Shootings in the United Statesocs-bp-school-shootings-dashboard
Exploring CO2 emissions across timeocs-bp-co2-emissions
Exploring global patterns of dietary behaviors associated with health riskocs-bp-diet

Why Use OCSdata?

All case study data is available in the respective OCS GitHub repositories. However, case study users new to GitHub can find it a confusing process to access data from repositories. On top of that, users then must move the downloaded data into to the appropriate local directory. Overall, this process leaves room for error and acts as a barrier to introductory level students. Troubleshooting these errors can be a headache for both students and instructors and eats away at valuable learning time. OCSdata is an R package that bridges the gap from web-browser to Rstudio, allowing users to automatically download the data they need with simple functions all within R.

This package is licensed under the terms of the MIT license.

Copy Link

Version

Install

install.packages('OCSdata')

Monthly Downloads

260

Version

1.0.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Carrie Wright

Last Published

August 20th, 2021

Functions in OCSdata (1.0.2)

load_wrangled_data

Internal Function
raw_data

Download Open Case Study Raw Data
zip_ocs

Download Case Study Repository Zip File
wrangled_rda

Download Open Case Study Wrangled Data - RDAs
clone_ocs

Clone Case Study Repository
simpler_import_data

Download Open Case Study Simpler Import Data
wrangled_csv

Download Open Case Study Wrangled Data - CSVs
imported_data

Download Open Case Study Imported Data
clone_ocs_repo

Internal Function
OCSdata

OCSdata: A package for downloading data from the 'Open Case Studies' repository
extra_data

Download Open Case Study Extra Data
load_repo

Internal Function
load_raw_data

Internal Function
load_imported_data

Internal Function
load_simpler_import

Internal Function
load_extra_data

Internal Function