Reproducible Reporting: Generating Dynamic Documents with R+RStudio
Contemporary life science is plagued by reproducibility issues. This workshop covers some of the barriers to reproducible research and how to start to address some of those problems during the data management and analysis phases of the research life cycle. In this workshop we will cover using R and dynamic document generation with RMarkdown and RStudio to weave together reporting text with executable R code to automatically generate reports in the form of PDF, Word, or HTML documents.
Date: September 29, 2015
Time: 1:00pm - 5:00pm
Location: Health Sciences Library, Carter Classroom
Pre-requisites:
- This is not a beginner course. This workshop requires basic familiarity with R: data frames, importing/exporting data, and plotting. You can refresh your R knowledge with DataCamp's Intro to R or TryR from CodeSchool.
- Bring a laptop to the course with the software installed as detailed below.
Registration: Click here.
Course material:
- Course materials: Check back after course.
- Markdown/RMarkdown reference: bioconnector.org/markdown.
Before coming
You must bring a laptop with the necessary software installed to the course. Please install the software below prior to the course - we will not have time during the workshop to troubleshoot installation issues. Please email me (sd...@virginia.edu) if you have any trouble.
Software setup
Note: R and RStudio are separate downloads and installations. R is the underlying statistical computing environment, but using R alone is no fun. RStudio is a graphical integrated development environment that makes using R much easier. You need R installed before you install RStudio.
- Download data. Download the
gapminder.csv
andmalebmi.csv
files from bioconnector.org/data. Save them somewhere easy to find. Optionally, open them up in Excel and look around. - Install R. You'll need R version 3.1.2 or higher. Download and install R for Windows or Mac OS X (download the latest R-3.x.x.pkg file for your appropriate version of OS X).
- Install RStudio. Download and install the latest stable version of RStudio Desktop. Alternatively, download the RStudio Desktop v0.99 preview release (the 0.99 preview version has many nice new features that are especially useful for this particular workshop).
- Install R packages. Launch RStudio (RStudio, not R itself). Ensure that you have internet access, then enter the following commands into the Console panel (usually the lower-left panel, by default). Note that these commands are case-sensitive. At any point (especially if you've used R/Bioconductor in the past), R may ask you if you want to update any old packages by asking
Update all/some/none? [a/s/n]:
. If you see this, typea
at the propt and hitEnter
to update any old packages. If you're using a Windows machine you might get some errors about not having permission to modify the existing libraries -- don't worry about this message. You can avoid this error altogether by running RStudio as an administrator.
# Install packages from CRAN
install.packages("dplyr")
install.packages("ggplot2")
install.packages("tidyr")
install.packages("knitr")
install.packages("rmarkdown")
You can check that you've installed everything correctly by closing and reopening RStudio and entering the following commands at the console window:
library(dplyr)
library(ggplot2)
library(tidyr)
library(knitr)
library(rmarkdown)
These commands may produce some notes or other output, but as long as they work without an error message, you're good to go. If you get a message that says something like: Error in library(packageName) : there is no package called 'packageName'
, then the required packages did not install correctly. Please do not hesitate to email me prior to the course if you are still having difficulty.
Additional setup steps required for the reproducible research / dynamic documents workshop:
- First, launch RStudio (not R). Click File, New File, R Markdown. This will tell you that you need to install additional packages (knitr, yaml, htmltools, caTools, bitops, and rmarkdown). Click "Yes" to install these.
- Sign up for a free account at RPubs.com.
- If you want to convert to PDF, you will need to install a LaTeX typesetting engine. This differs on Mac and Windows. Note that this part of the installation may take up to several hours, and isn't strictly required for the workshop.
- Windows LaTeX instructions:
- Download the installer using this link. It is important to use the full installer, not the basic installer. Run the installer .exe that you downloaded.
- Run the installer twice, making sure to use the Complete, not Basic, installation:
- First, When prompted, select the box to "Download MiKTeX." Select the closest mirror to your location. If you're doing this from Charlottesville, the United States / JMU mirror is likely the closest. This may take a while.
- Run the installer again, but this time select "Install" instead of "Download." When prompted "Install missing packages on-the-fly", drag your selection up to "Yes."
- Mac LaTeX instructions:
- Download the installer .pkg file using this link. This is a very large download (>2 gigabytes). It can take a while depending on your network speed.
- Run the installer package.
- Windows LaTeX instructions: