Reproducible Manuscripts in R

Boston College

Jason Geller, PH.D.(he/him)

2025-08-11

The Credibility Revolution

Open Science


  • Being open and transparent across all stages of the research process

    • Key principles:

      • Open access

      • Open data

      • Open code


Open Science in Practice: Reproducible Manuscripts

Elements of Reproducible Research(Stodden et al.)
  • Today we are going to focus on reproducible manuscript

Typical workflow

  1. Do your analyses
  2. Open a program (e.g., Word)
  3. Copy-paste results and figures/tables
  4. Manually format your results and citations

The Problem

Word

Inside

Word issues

  • A .docx file is a compressed folder with lots of files
    • Your text is buried in with a lot of formatting information
  • Not reproducible
    • Code is divorced from writing
  • Difficult to maintain
    • Errors!
  • What do I share?
    • Lack of transparency

What Do We Want?

  • Combine narrative with code (literate programming)

  • Automatically generate figures and tables

  • Automatically render results in text

  • Format the content into a scientific paper (including citations!)

  • Something that looks pretty!

  • Rinse & repeat

Hello Quarto!

  • Open source publishing system designed for reproducibility
  • Unify and extends the R Markdown ecosystem

The Quarto hexagon logo.

Big Universe

  • For EVERYONE
    • Develop and switch formats without hassle

Hello Quarto!

What is a Quarto?

How Quarto Works

Quarto handles literate programming by using a series of programs:

How Quarto Works (Source)

  • knitr executes all code chunks and creates a new markdown (.md) file
  • pandoc takes the markdown file generated and converts it to the desired format.
  • Render inside of RStudio handles the interaction.

Let’s Write a Manuscript!

Before We begin

Always start a new project folder!

  • Creating a Quarto manuscript

    • RStudio: New Project > New Directory > Quarto Manuscript
    • Positron: New File > Quarto Project > Manuscript Project

Packages

library(palmerpenguins) # penguins
library(quarto) # qmd 
library(rmarkdown) # markdown
library(tidyverse) # data wrangling
install.packages('tinytex') # for use with pdf 
tinytex::install_tinytex()
# to uninstall TinyTeX, run tinytex::uninstall_tinytex()
  • You should also have Zotero installed along with Better BibTeX (nice, but not necessary)

Overview of a Quarto Document

Create a Quarto Document

In the top left, click the White Plus and select “Quarto Document…”

Drop down menu containing Quarto Document creation button

Creating a new Quarto Document

In the new prompt, enter a title, author name, and press “Create”

New quarto document wizard allowing a title and author information to be set.

New Document Options

Source vs. Visual Mode

Figure showing what a Quarto document looks like in Source Editing Mode.

Source Editing Mode

Figure showing what a Quarto document looks like in Visual Editing Mode.

Visual Editing Mode

Annotated Quarto Document

Annotated figure that describes the different sections of a Quarto document while in the source editor mode.

Annotated sections of the “Hello Quarto” document related to document information, text formatting, and code execution

Output of a Quarto Document

Image showcasing how the source code of the document translated over into the rendered product.

Annotated source to output of the “Hello Quarto” document

Metadata & Header (YAML)

  • The YAML header cotains basic metadata and rendering instructions
---
title: My Reproducible Manuscript
authors:
  - name: Norah Jones
    affiliation: The University
    roles: writing
    corresponding: true
bibliography: references.bib
format: html
---
  • Wait… what’s the YAML acronym?

    • Originally: “Yet Another Markup Language”

    • Later: “YAML Ain’t Markup Language”

  • Set global manuscript options with key-value pairs

Code

```{r}
#| eval: true
1 + 1
```
[1] 2

Text

Section

This is a simple placeholder for the manuscript's main document [@knuth84].

Writing in Markdown (NEXT)