A Minimal Introduction to Reproducible Research
This is a minimal introduction to reproducible research, including data management and handling data in R, compiled for the Biological Sciences BSc(Honours) class at the University of Cape Town.
This really is a minimalist introduction. We only have a week! I’ll focus on providing a broad overview of the general framework and motivation for reproducible research (including good data management), teaching a few practical skills along the way.
Mostly this is not fun and exciting, but it is important stuff for any biologist to know. I’ll try my best to make it interesting! Hopefully by the end of the module you’ll see the value in it all - both for you as an individual and for science and society in general.
“Let us emphasize again this obvious conclusion: a scholar’s positive contribution is measured by the sum of the original data that [they] contribute… Hypotheses come and go but data remain. Theories desert us, while data defend us. They are our true resources, our real estate, and our best pedigree. In the eternal shifting of things, only they will save us from the ravages of time and from the forgetfulness or injustice of [people]. To risk everything on the success of one idea is to forget that every fifteen or twenty years theories are replaced or revised. So many apparently conclusive theories in physics, chemistry, geology, and biology have collapsed in the last few decades!” - Santiago Ramón y Cajal, 1906 Nobel Laureate, from Advice for a Young Investigator 1898 (Ramón y Cajal 1999)
The core outcomes/concepts I hope you’ll come away with:
- Familiarity with the concepts and understand the need for Open, Reproducible Science
- Familiarity with The Data Life Cycle
- Some data management and handling skills
These will be held live in person in BIO LT1 from 10AM to 12PM from the 12th to the 16th February unless otherwise announced on Amathuba.
I’ll be adding to (and mostly teaching from) these online course notes as we go along.
The schedule of lectures (and readings) is as follows:
- Monday, 12th Feb - Reproducible Research (Baker 2016; Peng 2011; Markowetz 2015)
- Tuesday, 13th Feb - Data Management (Michener and Jones 2012)
- Wednesday, 14th Feb - GitHub, Tidy Data and Data Wrangling (Wickham 2014; Wickham et al. 2019)
- Thursday, 15th Feb - Tidy Data and Data Wrangling continued (your turn)
- Friday, 16th Feb - We can discuss if you need me available to help. Possibly online.
A draft Data Management Plan (DMP) for your Honours Project (or mock project) using UCT’s Online DMP Tool. Please use the “University of Cape Town (UCT) - Full DMP” template.
A GitHub repository containing suitably named sub-folders, data files (if small) and the R scripts (that you’ll develop based on Wednesday’s tutorial), all in line with best practice as per the content of this module.
- More about the R script during the Tidy data tutorial, but it must be easily executable by one of your classmates, and output your data in tidy format and a summary figure of some kind.
- Since you may not want your data to be public, it is best to create a private repository and invite me as a collaborator. If your data are large (>5MB), then it’s best to create and only upload a smaller subset of the data. Note that your R script must still work with the reduced dataset, since part of your mark will be based on whether your script runs and the output reproducible.
- Lastly, I’d like you to spend some time reading up about reproducible research and data management (preferably relevant to our field) and to share any interesting resources you find - a link to a paper, news article, blog, tutorial, etc - with a 50 to 200 word summary of what it is and why its relevant and interesting. These will be collected and shared with the class either via Google Forms or GitHub (just as soon as I’ve set it up…).
For the data wrangling exercise and the second deliverable, we’ll be using the R statistical programming language and the Git version control system. We’ll also be using an integrated development environment (IDE) for each: RStudio and GitHub, respectively.
If you already have these installed and set up, please make sure you have the latest versions, and check that your installations are working! Please also make sure you have installed (and/or updated) the Tidyverse set of R packages. It can be installed using the code
install.packages("tidyverse")and updated using
The installation and setup can be a bit long-winded, but once done you should be good to go until you change or reformat your computer. The steps below are my summary and (hopefully) more intuitive adaptation of the instructions provided for setting up GitHub and version control with R. If my steps don’t work its probably best to read up there, or at Happy Git with R.
First we’ll start with the necessary software.
- Download and install the latest version of R
- Download and install the latest free version of RStudio Desktop
- Download and install the latest version of Git - accept all the defaults
- Create a GitHub account
- Run through the 10 minute GitHub tutorial that is offered when you activate your GitHub Account (It’ll really help you get the idea behind what Git does!)
Now you have RStudio, R and Git installed, and you have a working GitHub account that lets you do stuff online, but what remains is to get GitHub working locally and configuring RStudio to use GitHub. If any of the following doesn’t work, have a look at the installation section of Happy Git with R to troubleshoot:
- Install GitHub CLI (Command Line Interface).
- Open RStudio.
- Select the
Terminaltab (top left, next to
gh auth login, then follow the prompts:
- When prompted for your preferred protocol for Git operations, select
- When asked if you would like to authenticate to Git with your GitHub credentials, enter
- When asked how you would like to authenticate select
Login with web browser
- Copy the 8-digit code and hit
- Github.com will open in your internet browser - paste the code and hit enter
- If any of these steps don’t work, just start again with
gh auth loginin Terminal
Now that GitHub is starting to enforce 2-factor authentication, you may also need to do the following (especially if you get login issues at the end of step 10):
- We need to add a “personal access token” (PAT) which is generated by GitHub and added to R. We’ll manage this using
library(usethis)as it simplifies things. See this article for a full explanation.
- First, install the package by running
install.packages("usethis")in the R console
- Second, create a Github authentication token by running
usethis::create_github_token()in the R console
- Follow the prompts. Give the token a sensible name like “personal-laptop-rstudio-git” so you can work out what it is if you need to later
- Copy the code displayed - You will not be able to see it again!
- Third, run
gitcreds::gitcreds_set()in the R console
- When prompted, paste your token into R
- First, install the package by running
- In RStudio
- Go to
Global Options(from the
- Make sure
Enable version control interface for RStudio projectsis on
- If necessary, enter the path for your Git or SVN executable where provided (this shouldn’t be needed, but may)
- Restart RStudio
Lastly, you need to install the Tidyverse set of R packages. This can be done using the code