From Code to Paper: Reproducible Research with Quarto

Betsabe Cohen (BA Sociology)

Núcleo de Innovación Social - Buenos Aires Argentina

Hello/ Hola!/ Namaste

My name is Betsabé Cohen I’m a sociologist and data analyst from Buenos Aires Argentina.

👩🏻‍🎓 I am currently a Masters student in Statistics at University of Tres de Febrero.


I’m currently organizer at:

RLadies Buenos Aires: A global organisation that promotes gender diversity in the R community


Núcleo de Innovación Social
: An inter-disciplinary research and development team in social sciences and technology.

Agenda

  • Why Reproducibility?

  • What is Quarto?

  • Core Use Cases: a short walk around

  • Academic Production with Quarto Journal and Manuscripts

    • Journal Templates

    • Quarto Manuscript Projects

    • Citations, Cross references, and authoring

  • Learning More

Over shoulders of giagants

This presentation is based on:

  • Quarto Manuscripts official documentation

  • “Slides and materials for the”Reproducible Manuscripts with Quarto” talk at posit::conf(2023). by Mine Çetinkaya-Rundel

  • Quarto for Academics video on YouTube by Mine Çetinkaya-Rundel and Posit

  • R/Medicine: Quarto for Reproducible Medical Manuscripts by Mine Cetinkaya-Rundel webinar in youtube video

  • The Turing Way Community, & Scriberia.(2024) on https://book.the-turing-way.org/

Why Reproducibility?

What do we mean by reproductibility

The Turing Way project illustration by Scriberia. Used under a CC-BY 4.0 licence. DOI: The Turing Way Community & Scriberia (2024).

The Turing Way project illustration by Scriberia. Used under a CC-BY 4.0 licence. DOI: The Turing Way Community & Scriberia (2024).

Reproducible is distinct from replicable, robust and generalisable

How the Turing Way defines reproducible research

How the Turing Way defines reproducible research

Open Research

  • Open Data

  • Open Source Software (as R!)

  • Open Hardware

  • Open Access

  • Open notebooks (show the world how you do it with Rscripts and Quarto Manuscripts!)

The Turing Way project illustration by Scriberia. Used under a CC-BY 4.0 licence. DOI: The Turing Way Community & Scriberia (2024).

The Turing Way project illustration by Scriberia. Used under a CC-BY 4.0 licence. DOI: The Turing Way Community & Scriberia (2024).

What is Quarto?

Analyze. Share. Reproduce

  • An open-source scientific and technical publishing system

  • Create dynamic content with Python, R, Julia, and Observable.

  • Publish reproducible, production quality articles, presentations, dashboards, websites, blogs, and books in HTML, PDF, MS Word, e Pub, and more.

  • Share knowledge and insights organization-wide by publishing to Posit Connect, Confluence, or other publishing systems.

  • Write using Pandoc markdown, including equations, citations, cross refs, figure panels, call-outs, advanced layout, and more.

Quarto General Workflow

“Artwork from”Hello, Quarto” keynote by Julia Lowndes and Mine Çetinkaya-Rundel, presented at RStudio Conference 2022. Illustrated by Allison Horst.”

Quarto for R and other languages

“Artwork from”Hello, Quarto” keynote by Julia Lowndes and Mine Çetinkaya-Rundel, presented at RStudio Conference 2022. Illustrated by Allison Horst.”

Use Cases

  • 🗃️Dynamic Documents

  • 🌄Beautiful Publications

  • 🧪Scientific Markdown

  • 🕸️Websites and Books

  • 📽️Interactivity

Take a visit to Quarto Gallery here

A short walk around

Install Quarto

Create a Quarto File in a project we already have in our computer

Create a New Quarto Project

General folder structure in a Quarto Project

Quarto file general structure

Visual mode vs Source mode

Visual mode shortcuts

Insert Code Chuncks

Code cuncks options

Code Chuncks Options

You can add Quarto options to code cells by adding a #| comment to the top, followed by the option in YAML syntax. For example, adding the echo option with the value true would look like this:

The echo option describes whether the code is included in the rendered article. If you make this change and save index.qmd, you’ll see this code now appears in the article.

Code chunck options guide

You can find a list of all the code cell options available on the Knitr Code Cell reference page at https://quarto.org/docs/reference/cells/cells-knitr.html

Code cuncks options from YAML

Quarto for manuscripts and journal articles

Quarto can …

  • be authored in your favorite code editor

  • apply journal styles to your outputs with Quarto extensions

  • orchestrate multiple inputs and outputs with embedded computing using a new Quarto project type: manuscript

  • produce manuscripts in multiple formats (including LaTeX or MS Word formats required by journals), and give readers easy access to all of the formats through a website

  • publish computations from one or more notebooks alongside the manuscript, allowing readers to dive into your code and view it or interact with it in a virtual environment

  • publish to GitHub Pages, Netlify, and more

Journals vs Manuscripts

In Quarto, a journal refers to a single document, potentially with embedded computations and visualizations, designed for publication in a journal format.


A manuscript, on the other hand, represents a collection of Quarto documents, potentially including multiple chapters, that are intended to be assembled into a book-like structure.

Journals

Intsalling the templates from your terminal

How does the journal template file looks like

Rendering a Journal paper

Getting started with a manuscript: create a manuscript project

  • Start from scratch

    • in your terminal write quarto create project manuscript <name>
    • then start adding manuscipt content or…
  • Start with a sample from https://quarto.org/docs/manuscripts


Tip

Learn how to Track your project with Git and host on GitHub for happy publishing.

Your Turn! Option 1

If you already have a peper of your own (with differnt r files with code) go to your RStudio Terminal and create a new project from scratch

Terminal
quarto create project manuscript indo-rct

Creating project at /Users/mine/indo-rct:
  - Created _quarto.yml
  - Created index.qmd
  - Created references.bib
 ? Open With
   vscode
  rstudio
   (don't open)

Your Turn! Option 2

If you wanna follow along the same structure we are going to you can copy the repo from github repo

https://github.com/quarto-ext/manuscript-template-rstudio/tree/main

{fig-align = “center”}

Your turn!: Redy steady go!

👍 Please sign me with when you are ready.

Quarto manuscript: minimal folder structure

Quarto manuscript: minimal manuscript _quarto.yml

_quarto.yml
project:
  type: manuscript

manuscript:
  article: index.qmd

format:
  html:
    comments:
      hypothesis: true
  docx: default
  jats: default

  # (other formats)
  # pdf: default
execute:
  freeze: true

Basic workflow

The basic workflow for writing a manuscript in Quarto is to make changes to your article content (the index.qmd if you are following the example), preview the changes with Quarto, and repeat.

How does it look like once render?

Your Turn: Render your first qmd manuscript

  • Open index.qmd.
  • Render and preview the manuscript by hitting the Render button located in the menu bar of the editor
  • You’ll see some output from Quarto in the Background Jobs pane and then a live preview will appear in the Viewer pane.
  • Change the title of your index.qmd
  • Save the file, re-render, and you’ll see the preview update.

Your turn!: Redy steady go!

👍 Please sign me with when you are ready.

One qmd to rule all formats

{fig-align = “center”}

One qmd to rule all formats

_quarto.yml
format:
  html:
    comments:
      hypothesis: true
  docx: default
  jats: default
  plos-pdf:
    keep-tex: true

Setting the Front matter of your index.qmd

_index.qmd

title: La Palma Earthquakes
author:
  - name: Steve Purves
    orcid: 0000-0002-0760-5497
    corresponding: true
    email: steve@curvenote.com
    roles:
      - Investigation
      - Project administration
      - Software
      - Visualization
    affiliations:
      - Curvenote
  - name: Rowan Cockett
    orcid: 0000-0002-7859-8394
    corresponding: false
    roles: []
    affiliations:
      - Curvenote
keywords:
  - La Palma
  - Earthquakes
abstract: |
  In September 2021, a significant jump in seismic activity on the island of La Palma (Canary Islands, Spain) signaled the start of a volcanic crisis that still continues at the time of writing. Earthquake data is continually collected and published by the Instituto Geográphico Nacional (IGN). ...
plain-language-summary: |
  Earthquake data for the island of La Palma from the September 2021 eruption is found ...
key-points:
  - A web scraping script was developed to pull data from the Instituto Geogràphico Nacional into a machine-readable form for analysis
  - Earthquake events on La Palma are consistent with the presence of both mantle and crustal reservoirs.
date: last-modified
bibliography: references.bib
citation:
  container-title: Earth and Space Science
number-sections: true
---

Using computations in the body of youtr text

You can use computed values directly in your article text using the syntax `{r} expr`. For example, consider this line in index.qmd:

Based on data up to and including 1971, eruptions on La Palma happen every `{r} round(avg_years_between_eruptions, 1)` years on average.

When rendered, it displays as:

Based on data up to and including 1971, eruptions on La Palma happen every 79.8 years on average.

Code chuncks for computations using the lable and fig- options

```{r}
#| label: fig-timeline
#| fig-cap: Timeline of recent earthquakes on La Palma
#| fig-alt: An event plot of the years of the last 8 eruptions on La Palma.
#| fig-height: 1.5
#| fig-width: 6
par(mar = c(3, 1, 1, 1) + 0.1)
plot(
  eruptions, rep(0, n_eruptions), 
  pch = "|", axes = FALSE
)
axis(1)
box()
```

Citations

references.bib
@article{marrero2019,
  author = {Marrero, Jos{\' e} and Garc{\' i}a, Alicia and Berrocoso, Manuel and Llinares, {\' A}ngeles and Rodr{\' i}guez-Losada, Antonio and Ortiz, R.},
  journal = {Journal of Applied Volcanology},
  year = {2019},
  month = {7},
  pages = {},
  title = {Strategies for the development of volcanic hazard maps in monogenetic volcanic fields: the example of {La} {Palma} ({Canary} {Islands})},
  volume = {8},
  doi = {10.1186/s13617-019-0085-5},
}

Citations


Studies of the magma systems feeding the volcano, such as @marrero2019, have proposed ...


When rendered, it displays as:

Studies of the magma systems feeding the volcano, such as Marrero et al. (2019), have proposed

Citations

… and when hovering over the citation text it reveals the full reference details allowing reader to click on the citation and take it to the reference in the References section at the end of the article:

Citations

Another common style is to place the citation within parentheses at the end of a sentence. You can achieve this by enclosing the citation syntax in square brackets [. For example,

A prior study of the magma systems feeding the volcano proposed that there are two main magma reservoirs feeding the Cumbre Vieja volcano [@marrero2019].


When rendered, it displays as:

A prior study of the magma systems feeding the volcano proposed that there are two main magma reservoirs feeding the Cumbre Vieja volcano (Marrero et al. 2019).

Citations

Tip

Quarto support differnt syntax variotions to include page numbers, chapters, exclude author names and other cool posibilities. You can learn more about it the Citation documentation at https://quarto.org/docs/authoring/citations.html

Your Turn! Add a citation to your bib file and use it

  • Go to your bib file and add a citation
  • Go back to your index.qmd file and use the citation
  • Render your file and chevck the changes

Your turn!: Redy steady go!

👍 Please sign me with when you are ready.

Cross References

Labeled as…

@fig-timeline

Should be use used as

Eight eruptions have been recorded since the late 1400s (@fig-timeline).

And will look something like

Eight eruptions have been recorded since the late 1400s (Figure 1).

Cross References element and prefix

  • Figure fig- and will render as Figure 1

  • Table tbl- and will render as Table 1

  • Equation eq- and will render as Equation 1

  • Section sec- and will render as Section 1

Warning

To cross reference sections your document YAML header must also include number-sections: true You can add a label to a section heading in curly braces after the heading, e.g ## Data & Methods {#sec-data-methods} and the you can then reference this section in the text by adding the text and the @ reference like Data and methods are discussed in @sec-data-methods.

Cross Reference in visual mode

Static Figues and images

To include a figure from a file, the markdown syntax looks like:

![Map of La Palma](images/la-palma-map.png)

By using #fig-name-of-image inside curly braces following the image path you can provide the reader a label for cross references. For eg.

![Map of La Palma](images/la-palma-map.png){#fig-map fig-alt="A map of the Canary Islands. The second most west island, La Palma, is highlighted."}

Tip

It is recomended to store your in an folder named images/. Your images can be anywhere inside your manuscript project directory, just make sure you include the full path to the image, relative to the location of index.qmd.

Authring embeded code from other notebooks

```{r}
{{< embed notebooks/explore-earthquakes.qmd#fig-spatial-plot >}}
```
  • Create a folder for your notbooks
  • Add notebooks for calculations/ charts results, etc.
  • Add refreces in your manuscript index.qmd
  • Use figures with fig- labels

Authring embeded code from other notebooks

Publising

To publish your site on GitHub Pages simply tipe

Terminal
quarto publish

Choose GitHub Pages or the platform you prefer.

You can learn more about publishing at https://quarto.org/docs/publishing/

What else can I do with Quarto? Presentations 📺

What else can I do with Quarto? Dasboards! 📈

What else can I do with Quarto? Your Personal website 🌐

What else can I do with Quarto? Your First Book 📖

Thank you!


www.linkedin.com/in/betsabe1984


betsabecohen@gmail.com