Reproducibility,
Version Control, and
Literate Programming

2026 DSS Bootcamp

Colin Rundel

Some examples

Bad spreadsheet merge kills depression paper, quick fix resurrects it

The authors informed the journal that the merge of laboratory results and other survey data used in the paper resulted in an error regarding the identification codes. Results of the analyses were based on the data set in which this error occurred. Further analyses established the results reported in this manuscript and interpretation of the data are not correct.

  • Original conclusion: Lower levels of CSF IL-6 were associated with current depression and with future depression […].

  • Revised conclusion: Higher levels of CSF IL-6 and CSF IL-8 were associated with current depression […].

Seizure study retracted after authors realize data got “terribly mixed”

From the authors of Low Dose Lidocaine for Refractory Seizures in Preterm Neonates:

The article has been retracted at the request of the authors. After carefully re-examining the data presented in the article, they identified that data of two different hospitals got terribly mixed. The published results cannot be reproduced in accordance with scientific and clinical correctness.

The error was detected when the authors later used lidocaine for the same problem and did not get the same result, which led them to re-examine the original data.

Potti case

Anil Potti was a rising star cancer researcher here at Duke in the School of Medicine. His lab’s research focused on precision oncology (genomic signatures that could be used to predict patient response to chemotherapy).

  • Work was published in high-profile journals and received significant funding and attention; clinical trials using some of these results were also conducted.

  • Early whistleblower complaints from a medical student were dismissed; the student was persuaded not to report their concerns to the funding agency

  • Extensive work by statisticians (Baggerly and Coombes) at MD Anderson Cancer Center showed strong evidence that data were fabricated, manipulated, and misrepresented.

  • Downfall (in part) was triggered by falsifications of Potti’s CV (claimed to have been a Rhodes Scholar)

  • Ultimately 11 papers were retracted

Clusterfake

Shu, Mazar, Gino, Ariely, & Bazerman (2012), “Signing at the beginning makes ethics salient …” (PNAS) was an influential paper that claimed to have found that signing a declaration of honesty at the beginning of a survey reduced dishonest self-reports. It involved multiple independent studies and was widely cited.

The paper was retracted in 2021 due to concerns about data fabrication and manipulation in one of the studies.

Subsequently, additional issues were discovered in a different study by a different author within the same paper.

Practice

Reproducibility in practice

  • Is the original data intact and available?

  • Are the tables and figures reproducible from the code and data?

  • Does the code actually do what you think it does?

  • In addition to what was done, is it clear why it was done? (e.g., how were parameters chosen?)

  • Can the code be used for other data, especially future updates to the current data?

  • Can you extend the code to do other things?

Reproducibility in science

Ambitious goal

We need an environment where:

  • data, analysis, and results are tightly connected, or better yet, inseparable,

  • reproducibility is built in,

    • the original data remains untouched
    • all data manipulations and analyses are inherently documented
  • all procedures are human readable and understandable.

Donald Knuth “Literate Programming” (1983)

Let us change our traditional attitude to the construction of programs: Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do.

The practitioner of literate programming […] strives for a program that is comprehensible because its concepts have been introduced in an order that is best for human understanding, using a mixture of formal and informal methods that reinforce each other.

  • These ideas have been around for years!

  • Tools for putting them into practice have also been around.

  • They have never been as accessible as they are now.

Reproducible data analysis stack


Scriptability

R / Python / Julia




Literate Programming

RMarkdown / Quarto
Jupyter / Marimo

Version Control

Git / GitHub


Getting set up

GitHub account

  • Create a GitHub account (unless you already have one) on https://github.com/

  • One day you might want to show off your work, so choose a username you will be ok with disclosing to a future employer.

Some suggestions:

  • Incorporate your actual name.

  • Shorter is better than longer.

  • Be as unique as possible in as few characters as possible. In some settings GitHub auto-completes or suggests usernames.

  • Make it timeless. Don’t highlight your current university, employer, or place of residence.

  • Avoid words laden with special meaning in programming.

Accessing Posit Workbench

To get started as quickly as possible, the preferred method is to use DSS Workbench server(s).

To access Posit Workbench:

  1. Navigate to https://rstudio.stat.duke.edu
  2. Log-in with your Duke NetID and password.

If you are having trouble accessing Posit Workbench see the next slide.

DSS Workbench alternatives

If you cannot access RStudio via the DSS servers:

  • Make sure you are not using a custom DNS server

    • e.g. 1.1.1.1 or 8.8.8.8
  • Use a Docker container from Duke OIT

    1. Go to https://cmgr.oit.duke.edu/ and login
    2. Select Reserve a Container and find RStudio (statistics application with R Markdown and knitr support)
    3. Click the link under my reservations to create your environment
  • Install R and RStudio (or Positron) locally on your computer

    • Download R on your computer here
    • Download RStudio here
    • Download Positron here

Logging in to Workbench

git and GitHub

Why version control?

  • Simple formal system for tracking changes to a project over time

  • Time machine for your projects

    • Track blame and/or praise
    • Remove the fear of breaking things
  • Critical for collaboration

    • Include past-you + AI
  • Learning curve can be a bit steep, but when you need it you REALLY need it

Why git?

  • Distributed

    • Work online or offline
    • Collaborate with large groups
  • Popular and Successful

    • Active development
    • Shiny new tools and ecosystems
    • Fast
  • Tracks any type of file

  • Branching

Verifying git exists

git is already installed on the server(s). In the terminal tab you can verify this by running:

[cr173@hypatia ~]$ git --version
## git version 2.55.0


[cr173@hypatia ~]$ which git
## /usr/bin/git

Git sitrep

Within R we can also use the usethis package to get a helpful summary of the current git configuration,

usethis::git_sitrep()
── Git global (user) 
• Name: <unset>
• Email: <unset>
✖ Git user's name and email are not set.
ℹ Configure using `use_git_config(user.name = "<your name>", user.email = "<your email>")`.
• Global (user-level) gitignore file:
• Vaccinated: FALSE
ℹ See `usethis::git_vaccinate()` to learn more.
• Default Git protocol: "https"
• Default initial branch name: "main"

── GitHub user 
• Default GitHub host: "https://github.com"
• Personal access token for "https://github.com": <unset>
☐ To create a personal access token, call usethis::create_github_token().
☐ To store a token for current and future use, call gitcreds::gitcreds_set().
ℹ Read more in the Managing Git(Hub) Credentials article.

── Active usethis project: "/home/vis/cr173" ──

ℹ Active project is not a Git repo.

git and GitHub live demo

Configure git

The following will tell git who you are, and other common configuration tasks.

usethis::use_git_config(
  user.name = "Colin Rundel",
  user.email = "rundel@gmail.com",
  init.defaultBranch = "main",
  pull.rebase = "false"
)

You will need to do this configuration once on each environment (home directory) you use git (e.g. the server(s), your laptop, the DCC).

This can also be done via the terminal with,

git config --global user.name "Colin Rundel"
git config --global user.email "rundel@gmail.com"
git config --global init.defaultBranch main
git config --global pull.rebase false

Configure git verification

To verify you configured git correctly, run

usethis::git_sitrep()
── Git global (user) 
• Name: "Colin Rundel"
• Email: "rundel@gmail.com"
• Global (user-level) gitignore file:
• Vaccinated: FALSE
ℹ See `usethis::git_vaccinate()` to learn more.
• Default Git protocol: "https"
• Default initial branch name: "main"

── GitHub user 
• Default GitHub host: "https://github.com"
• Personal access token for "https://github.com": <unset>
☐ To create a personal access token, call usethis::create_github_token().
☐ To store a token for current and future use, call gitcreds::gitcreds_set().
ℹ Read more in the Managing Git(Hub) Credentials article.

── Active usethis project: "/home/vis/cr173" ──

ℹ Active project is not a Git repo.

You should see output similar to above with your details.

Configure SSH and GitHub (authentication)

We will be authenticating with GitHub using SSH via public / private keys. We can create a new key pair (if necessary) by running the following in RStudio’s console:

credentials::ssh_setup_github()
## No SSH key found. Generate one now?
##
## 1: Yes
## 2: No
##
## Selection: 1
## Generating new RSA keyspair at: /home/guest/.ssh/id_rsa
## Your public key:
##
##  ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC/wH7pT3UXdOMJSX2wMaPVTyGnYkS8OPmcfjct6h8Q+44/9UG3sOibjjUCxIxVeCWAoYFB0rDI3/Ljf2EWozLlpeGzAe7xsg6A+MHtUObZnfzXSB/NnOhZymD2u8Nh+py07aojVdKAPBkRH3nHA+rljidc3gXZkqseetYEI1N79OQUshp2P+Qm6Vab4I5OCnfAwLFkR7Sw7J9hvZN1qUmM0DB0WTWSlNmPSMsASMe/6Nz30IRoBh35Z7tgF79rlIW385giCkEeD20Le9EOueGoTWarJWylE1RWnUyig2mZ9JK/rYTw4KBXacPhBwn+MgGC+r8xY5IEX78xkeXW9q2z #<<
##
## Please copy the line above to GitHub: https://github.com/settings/ssh/new
## Would you like to open a browser now?
##
## 1: Yes
## 2: No
##
## Selection: 1

Getting started today

In order to get started, you need to obtain today’s files from GitHub. The steps below will give you access.

  1. Log in to GitHub

  2. Navigate to https://github.com/dukestatsci/computing_bootcamp_2026

  3. Fork the repository

  4. Copy the link under the Code button to clone with SSH.

  5. In Positron go to File > New Folder from Git

  6. Paste the ssh URL, that you copied in step 4, in the box under Repository URL

You now should have all the files in the repository in a directory on the server or your own computer.

Introduction to git

git Verbs (commands)

  • status - returns details about the current status of your git repository

  • add / rm - stage (or unstage) a local file with changes so that the changes will be saved when you commit.

  • restore - revert local changes that have not yet been committed

  • commit - save staged local changes

  • push - send local committed changes to a remote git instance

  • pull - collect committed changes from a remote git instance

Activity

We will now make sure that everything is working correctly by making changes to the README.md file in the repository.

  • Make a small change to README.md (e.g. add your name) and save the file.

  • Stage & commit that change using Positron’s git GUI

  • Push the changes to GitHub

  • Check that the changes are reflected on GitHub

Version control best practices

  • Commit early, often, and with complete code.

  • Write clear and concise commit messages.

  • Test code before you commit.

  • Use branches.

  • Communicate with your team.

git and GitHub resources

Literate programming with R Markdown and Quarto

What is markdown?

  • Markdown is a lightweight markup language for creating HTML (and other formatted) documents.

  • Markup languages are designed to produce documents from human readable text (and annotations).

  • Some of you may be familiar with LaTeX. This is another (less human friendly) markup language for creating pdf documents.

  • Why markdown is great:

    • Easy to learn and use.
    • Focus on content, rather than coding and debugging errors.
    • Once you have the basics down, you can get fancy via HTML, JavaScript, and CSS.
    • Used by R Markdown, Jupyter Notebooks, and Quarto

R Markdown / Quarto - Input

R Markdown:

---
title: "Untitled"
output: html_document
date: "2023-08-22"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars}
summary(cars)
```

## Including Plots

You can also embed plots, for example:

```{r pressure, echo=FALSE}
plot(pressure)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

Quarto:

---
title: "Untitled"
format: html
---

## Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.

## Running Code

When you click the **Render** button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

```{r}
1 + 1
```

You can add options to executable code like this

```{r}
#| echo: false
2 * 2
```

The `echo: false` option disables the printing of code (only output is displayed).

R Markdown / Quarto - Output

Something simple

Something fancy

R Markdown resources

Quarto resources

Quarto / RMarkdown demo

R packages

  • Packages are the fundamental units of reproducible R code. They include reusable R functions, the documentation that describes how to use them, and sample data.

  • In the following exercises we’ll use the tidyverse package.

    • The tidyverse is an opinionated collection of R packages designed for data science. All packages share an underlying design philosophy, grammar, and data structures.
    • The core tidyverse packages are ggplot2, tibble, tidyr, readr, purrr, dplyr, stringr, and forcats.
  • This package is already installed for you on the servers. If needed, you can install it by running the following in the Console:

    install.packages("tidyverse")

A note on environments

  • Your Quarto document and your Console do not share their global environments.

    • This is different than the computational model of Jupyter Notebooks!
  • This is good for reproducibility, but can sometimes result in frustrating errors.

  • This also means any packages or data needed for your analysis need to be loaded in your Quarto document as well.

Unvotes data analysis

To get started,

  • open examples/unvotes.qmd,

  • try Rendering the entire document and examine the results.

  • try changing one or more of the selected countries, re-render the document and observe any changes.

  • commit and push your changes to GitHub


R Markdown / Quarto suggestions

  • Remember to name your code chunks

  • Familiarize yourself with chunk options (https://yihui.org/knitr/options/)

    • Use global chunk options to reduce duplication
    • Using #| syntax enables tab completion for chunk options
  • Load packages at the start of a document, generally the chunk after your setup chunk

  • Familiarize yourself with various output formats: Make slides with revealjs, pdfs, books, etc.