Introduction to Quarto

Katja Kozjek

NBIS, SciLifeLab

14-Apr-2025

Quarto

An open-source scientific and technical publishing system

  • Quarto is a command line tool, not an R package
  • Quarto combine codes, comments, and other features to tell a story about your data
  • Quarto support numerous output formats
  • Quarto documents are fully reproducible


Installation

  • Install the latest quarto executable
  • R package quarto is a wrapper that runs quarto from R
  • If using RStudio, you need a version v2022.07.1 or newer
  • Visual Studio Code along with quarto extension is a great option too

Quarto notebook

Quarto file – a plain text file that has the extension .qmd

---
title: "Palmer penguins"
author: "Katja"
date: today
format: 
  html: 
    code-fold: true
    code-tools: true
    toc: true
    number-sections: true
execute:
  warning: false
---

# Meet the penguins
The `palmerpenguins` data contains size measurements for three penguin species 
observed on three islands in the Palmer Archipelago, Antarctica.

![](./images/lter_penguins.png)

The three species of penguins have quite distinct 
distributions of physical dimensions (@fig-penguins).

```{r packages}
#| label: load packages and data
#| warning: false
#| output: false
library(ggplot2)
library(palmerpenguins)
library(dplyr)
data(penguins, package = "palmerpenguins")
```

## Bill dimensions
```{r bill dimensions}
#| label: fig-penguins
#| warning: false
#| fig-cap: "Bill dimensions of penguins across three species."
#| fig-width: 10
#| fig-height: 5

penguins %>%
  ggplot(aes(x = bill_length_mm, y = bill_depth_mm)) +
  geom_point(aes(color = species, 
                 shape = species),
             size = 2) + 
  geom_smooth(method = "lm", se = FALSE, aes(color = species)) +
  scale_color_manual(values = c("darkorange","darkorchid","cyan4")) + 
  labs(color = "Species", shape = "Species") + 
  xlab("Bill length (mm)") + ylab("Bill depth (mm)") + 
  theme_bw()
```

Quarto document anatomy

YAML metadata

---
title: "Palmer penguins"
subtitle: "Intro to Quarto Exercise"
author: "Katja"
date: today
format: 
  html: 
    code-fold: true
    code-tools: true
    toc: true
    number-sections: true
execute:
  warning: false
---
  • Bracketed by ---
  • Defines document-wide options
  • Specifies the output format
  • Can include several parameters

Markdown text

  • Images, tables, text, etc.
  • Freely add and format text using markdown
# Meet the penguins
The `palmerpenguins` data contains size measurements for three penguin species 
observed on three islands in the Palmer Archipelago, Antarctica.

![](./images/lter_penguins.png)

The three species of penguins have quite distinct 
distributions of physical dimensions (@fig-penguins).

## Bill dimensions

Code chunks

  • Code blocks are called code chunks
  • Evaluate code and show its output
  • Specify global and/or local chunk options (e.g. figure dimensions)
  • Also works with other languages (e.g. Python)
## Bill dimensions
```{r bill dimensions}
#| label: fig-penguins
#| warning: false
#| fig-cap: "Bill dimensions of penguins across three species."
#| fig-width: 10
#| fig-height: 5

penguins %>%
  ggplot(aes(x = bill_length_mm, y = bill_depth_mm)) +
  geom_point(aes(color = species, 
                 shape = species),
             size = 2) + 
  geom_smooth(method = "lm", se = FALSE, aes(color = species)) +
  scale_color_manual(values = c("darkorange","darkorchid","cyan4")) + 
  labs(color = "Species", shape = "Species") + 
  xlab("Bill length (mm)") + ylab("Bill depth (mm)") + 
  theme_bw()
```

Rendering Quarto document

  • Live preview
    • From R console: quarto::quarto_preview("report.qmd")
    • From terminal: quarto preview report.qmd
  • Render
    • Interactively using the Render button
    • From R console: quarto::quarto_render("report.qmd")
    • From terminal: quarto render report.qmd

How rendering works?



Output formats

  • Reports and general documents (HTML, PDF, Jupyter Notebook, Microsoft Word)
  • Presentations (reveal.js, PowerPoint, Beamer)
  • Interactive documents (Observable, R Shiny)
  • Books, blogs and websites
  • Journal articles

Moving between output formats is straightforward

Document HTML

lesson-1.qmd

title: "Lesson 1"
format: html

Document PDF

lesson-1.qmd

title: "Lesson 1"
format: pdf

Presentation

lesson-1.qmd

title: "Lesson 1"
format: revealjs

Website

_quarto.yml

project:
  type: website

website: 
  navbar: 
    left:
      - lesson-1.qmd

Book

_quarto.yml

project:
  type: book

website: 
  navbar: 
    left:
      - lesson-1.qmd

Key advantages of Quarto

  • Text, code snippets, and visualizations in a single document
  • Supports multiple programming languages (R, Python, Julia, etc.)
  • Various output formats (HTML, PDF, presentations, etc.)
  • Compatible with multiple editors (RStudio, VS Code, Jupyter Lab, etc.)
  • Interactive elements (Shiny apps, HTML widgets, or JavaScript visualizations) can be incorporated directly into documents
  • Reproducible and transparent workflows
  • Easy collaboration and sharing

Sources

Thank you. Questions?