Introduction to Quarto

R Workshop
Author
Affiliation

Boston University

Published

February 6, 2025

Quarto

Introduction

Quarto documentation and gallery can be found on their website.

Quarto cheatsheet

Below are some examples of the features that were added to RMarkdown notebooks.

Additional text formatting:

Check boxes

Interrupted lists

  1. A list whose numbering continues after

  2. an interruption

Term definition

Quarto
An open-source scientific and technical publishing system

Show code and hide code in the output

By default the code is executed, displayed in the output and output is rendered under it:

Code
library(MASS)
data(cats)

str(cats)
'data.frame':   144 obs. of  3 variables:
 $ Sex: Factor w/ 2 levels "F","M": 1 1 1 1 1 1 1 1 1 1 ...
 $ Bwt: num  2 2 2 2.1 2.1 2.1 2.1 2.1 2.1 2.1 ...
 $ Hwt: num  7 7.4 9.5 7.2 7.3 7.6 8.1 8.2 8.3 8.5 ...

echo option allows to display the output, but not show the code

'data.frame':   144 obs. of  3 variables:
 $ Sex: Factor w/ 2 levels "F","M": 1 1 1 1 1 1 1 1 1 1 ...
 $ Bwt: num  2 2 2 2.1 2.1 2.1 2.1 2.1 2.1 2.1 ...
 $ Hwt: num  7 7.4 9.5 7.2 7.3 7.6 8.1 8.2 8.3 8.5 ...

eval option allows to display the code, but not evaluate it. Additionaly, if we set cold-fold option to true, the code chunk will be displayed and not “folded” under Code arrow:

str(cats)

Automatic Figure labeling

Figure 1 explores the impact of temperature on ozone level.

Code
library(ggplot2)
data(airquality)

ggplot(airquality, aes(Temp, Ozone)) + 
  geom_point() + 
  geom_smooth(method = "loess"
)
Figure 1: Temperature and ozone level.

Code Linking

The code-link option in the header enables hyper-linking of functions within code blocks to their online documentation

library(dplyr)

airquality %>%
  filter(!is.na(Ozone)) %>%
  mutate(Temp = (Temp-32)/9*5) %>%
  group_by(Month) %>%
  summarize( ave_temp = mean(Temp))
# A tibble: 5 × 2
  Month ave_temp
  <int>    <dbl>
1     5     19.3
2     6     25.7
3     7     28.8
4     8     28.9
5     9     24.9

Themes

There are currently 25 themes included in the Quarto. You can set a theme by adding a theme option to the header (e.g. theme: darkly)

More on themes, can be found Quarto’s HTML Themes webpage

Callouts:

Note

The callout-note can be used to draw attention to some information

Warning

The callout-warning can be used for warnings

Important

The callout-important can be to highligh important information

Tip with Title

This is an example of a callout with a title.

This is an example of a ‘folded’ caution callout that can be expanded by the user. You can use collapse="true" to collapse it by default or collapse="false" to make a collapsible callout that is expanded by default.