Chapter 4 Modifying open case studies
4.1 Learning Objectives
This chapter will cover how to modify the case studies to your own needs using the following methods:
- Modular case study use with the help of the
OCSdata
package - Modifying a case study with GitHub and RStudio
4.2 Modular use
Some educators may find that only certain sections of a case study are relevant to their specific needs. For example, a statistics teacher may want students to practice the skills covered in the data analysis section, but doesn’t have time to go through the whole case study. The case studies are designed to allow for such use. This educator and their students may jump right in to any case study section without working through any previous sections. This is made possible because the data files are saved at the end of each section. These data files are made available on the case study’s GitHub repository and may also be downloaded with the help of the OCSdata
package. See Chapter 2 for more details on the structure and organization of a case study data folder. The table below explains which data sub-folder and package function to use for each case study section.
Data Folder | Case Study Section | OCSdata Function |
---|---|---|
raw | Data Import | raw_data |
imported | Data Exploration, Data Wrangling | imported_data |
wrangled | Data Visualization, Data Analysis | wrangled_csv , wrangled_rda |
simpler_import | Data Import | simpler_import_data |
extra | Suggested Homework (?) | extra_data |
If you’d like to learn more about modular use of Open Case Studies you can read this thesis by former graduate student Michael Breshock Breshock (2021).
4.2.1 Example of Modular Use
The following steps illustrate how one would skip to a specific case study section. The data analysis section from the “Opioids in United States” case study is used for this example, but these directions apply for any section in any case study.
4.2.1.1 Steps for modular use
- Use the table of contents to navigate to the section of interest. Click on the arrow that reads “If you skipped the previous sections click here.”
- Follow the instructions provided to download the data files from the previous section either with
OCSdata
or manually through GitHub. We will now demonstrate each option.
4.2.1.2 Downloading data with OCSdata
:
- First install and load the
OCSdata
package:
install.packages("OCSdata") #only run once to install package
library(OCSdata) #run every new R session to load package
- Now download the wrangled data into your R environment using the following function command:
wrangled_rda("ocs-bp-opioid-rural-urban", outpath = getwd())
This command will download the wrangled data in .RDA format. You may also be downloaded wrangled data in .CSV format by replacing ‘wrangled_rda’ with ‘wrangled_csv’
- Load the RDA files with the following commands:
load(file = here::here("OCS_data", "data", "wrangled", "Annual_opioid_data.rda"))
load(file = here::here("OCS_data", "data", "wrangled", "county_info.rda"))
4.2.1.3 Manually Download Data from GitHub:
- Download the .RDA files available on the case study GitHub repository from here.
The CSV versions of the files may also be downloaded here, if preferred
Move the data files from your ‘Downloads’ folder to your R session’s current working directory (you can see what this is with
getwd()
).Load the RDA files with the following commands:
load(file = here::here("Annual_opioid_data.rda"))
load(file = here::here("county_info.rda"))
- All the data you need to work through the current section is now loaded into your environment. You are ready to work through the section of interest, without needing to work through any of the previous sections.
4.3 Modify a case study
The case studies are written in R Markdown documents and developed within an RStudio project. R Markdown documents are denoted with the file extension “.Rmd” and allow for the inclusion of code chunks and outputs in a written report. They are written using Markdown syntax. RStudio projects are used to organize the case studies. The knitr package “knits” the case study written in R Markdown and outputs the document as an HTML file. Open Case Studies uses these HTML files to post the case studies online. The entire case study project is contained in a GitHub repository which allows for easy distribution and version control. GitHub Pages is used to host the case study webpage from the case study repository.
Modifying a case study requires the following simple steps:
Use the
OCSdata
packagezip_ocs()
function to download the case study files without our git history. Alternatively, if you are familiar with GitHub and wish to you can clone or fork the case study repository from GitHub. See this section of chapter 2 for more information.In the repository folder, open the case study .Rproj file to open the project up in RStudio.
Edit the sections to be modified in the index.Rmd file.
Save your changes, then click on the “Knit” drop down menu in the top left corner of RStudio. Choose which file format you’d like to knit to.
- Distribute your modified case study as you please!
You can share HTML, PDF and Word files directly with your students or you can host your case study for free on GitHub using GitHub pages (“GitHub Pages Documentation” n.d.).
To do so, you will need to set up your version of the case study on GitHub. If you are new to GitHub, also be sure to check out Hester (n.d.).
These steps are demonstrated in the following video about modifying case studies:
4.4 Session info
## R version 4.0.2 (2020-06-22)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.3 LTS
##
## Matrix products: default
## BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.8.so
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=C
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## loaded via a namespace (and not attached):
## [1] compiler_4.0.2 magrittr_2.0.2 bookdown_0.24 htmltools_0.5.0
## [5] tools_4.0.2 yaml_2.2.1 jquerylib_0.1.4 stringi_1.5.3
## [9] rmarkdown_2.10 highr_0.8 knitr_1.33 stringr_1.4.0
## [13] digest_0.6.25 xfun_0.26 rlang_0.4.10 evaluate_0.14