What can I do with Quarto?

An introduction to reproducible research and reports

Nicola Rennie

About Me

My R journey (so far)

A stream graph showing the use of R for the author between 2014 and present day. The y-axis represents the general quantity of how often R was used, with no units. An increase is seen from 2019, and then more significantly in the last year.

What do I do at Jumping Rivers?

Consultancy Hex stickers for four common R packages

Training Cartoon of a teacher at the front of a class with a board showing an R

R Community Shiny in Production conference logo of a robot holding a spanner

Resources

What is Quarto?

What is Quarto?

Quarto is an open-source scientific and technical publishing system that allows you to combine text, images, code, plots, and tables in a fully-reproducible document. Quarto has support for multiple languages including R, Python, Julia, and Observable. It also works for a range of output formats such as PDFs, HTML documents, websites, presentations,…


That sounds a bit like R Markdown!

What about R Markdown?

R Markdown isn’t going anywhere but…

  • Quarto has better multi-language support

  • More user-friendly

  • Better control of the output layouts

Simple documents

Creating a document

Gif of creating a new quarto document

Rendering a document

Within RStudio IDE: click Render (or Ctrl+Shift+K)


Using {quarto}

library(quarto)
quarto_render("document.qmd")


Using the command line

quarto render document.qmd

What makes a Quarto document?

YAML header

---
title: "A very cool title"
format: html
---

Content

  • Text, links, images

  • Code, tables, plots

  • Equations, references

Output types

  • Documents: HTML, PDF, MS Word, Markdown

  • Presentations: Revealjs, PowerPoint, Beamer

  • Websites

  • Books

Code block options

Quarto vs R Markdown

```{r}
#| eval: false
#| warning: false
2+2
```


Comparing to R Markdown: `

```{r, warning=FALSE, eval=FALSE}
2 + 2
```


knitr::convert_chunk_header("document.qmd", output = identity)

Code block options

Code visibility options:

  • Hide the code
#| echo: false
  • Show the code
#| echo: true
  • Show the code and the YAML
#| echo: fenced

Code block options


```{r}
#| echo: fenced
#| eval: true
#| warning: false
#| error: false
#| output: asis
#| include: true
```

Code block options

Figure options:

```{r}
#| fig-alt: "Bar chart showing the number of lemurs for three different species"
#| fig-height: 7
#| fig-width: 10
#| fig-align: center
#| output-location: slide
g <- ggplot(data = lemurs, 
            aes(x = name, y = n, fill = name)) +
  geom_col()
g
```

Code block options

Bar chart showing the number of lemurs for three different species

Code block options

Output location:

```{r}
#| output-location: column
g
```

Code block options

Highlight code:

```{r}
#| eval: false
#| code-line-numbers: "3"
ggplot(data = lemurs, 
       aes(x = name, y = n, fill = name)) +
  geom_col() 
```

Global code block options

RMarkdown

```{r}
knitr::opts_chunk$set(echo = FALSE)
```

Quarto

---
title: "A very cool title"
format: html
execute:
  echo: false
---

Inline code

We can also include code inline, rather than as a separate chunk.

The total number of lemurs is `r sum(lemurs$n)`.

The total number of lemurs is 21859.

My favourite things (about Quarto)

Predictive YAML (and code block options)

Gif of predictive yaml in a quarto document

Journal articles

Templates: github.com/quarto-journals

---
title: "A very cool title"
format:
  pdf: default
  jss-pdf:
    keep-tex: true 
---

Writing LaTeX

---
title: "A very cool title"
format: html
---

\begin{equation}
\hat{e}_i = Y_i - \hat{Y}_i
\end{equation}

\[\begin{equation} \hat{e}_i = Y_i - \hat{Y}_i \end{equation}\]

Multiple columns


::: .columns
::: {.column width = "60%"}
The content for the first column goes here.
:::

::: {.column width = "40%"}
The content for the second column goes here.
:::
:::

Code animation

g <- ggplot(data = lemurs, 
            aes(x = name, y = n, fill = name)) +
  geom_col()

Code animation

g <- ggplot(data = lemurs, 
            aes(x = name, y = n, fill = name)) +
  geom_col() +
  scale_fill_brewer(palette = "Dark2")

Diagrams

```{dot}
graph G {
  qmd -- Knitr;
  qmd -- Jupyter;
  Knitr -- md;
  Jupyter -- md;
  md -- pandoc;
  pandoc -- HTML;
  pandoc -- PDF;
  pandoc -- Word;
  pandoc -- more;
}
```

Diagrams

G qmd qmd Knitr Knitr qmd–Knitr Jupyter Jupyter qmd–Jupyter md md Knitr–md Jupyter–md pandoc pandoc md–pandoc HTML HTML pandoc–HTML PDF PDF pandoc–PDF Word Word pandoc–Word more more pandoc–more

Resources


Questions?