WCHD Workshop – Quarto

Quarto

Quarto (the next generation of RMarkdown) enables you to weave together content and code into a finished product.

Image Source: Epi R Handbook

Quarto

If you’re familiar with Rmarkdown, you know how to use Quarto! (And if not, no worries, you’re about to learn)

What is Quarto good for?

  • Making automated reports or presentations - html, pdf, Word, Powerpoint formats
  • Making code, code snippets, etc. sharable and reproducible
  • Quick analyses that are documented and reproducible (and can include interactive graphs for example)
  • Make interactives, dashboards, websites, etc. (for internal or external purposes)

Quarto files

Quarto files have an ending of .qmd and are “rendered” into a document type of your choice.

  • Html (i.e. websites like the one for this workshop!) - this is probably the most flexible format! You can use html for many things, e.g. interactive dashboards, reports, code snippets, etc.
  • Web slides (like this!)
  • Powerpoint
  • Word
  • Pdf
  • And more! (latex, epub, wiki—complete list here)

Parts of the Document

  • The YAML Header: sets “global options” for the document
    • Different information for html or pdf output
  • Code Chunks: generate content for the document (figures, tables, etc.) or show examples of code
  • Text: formatted using Markdown

Learning by Doing

  • General Practice and Exploration
  • Specific Recreation

Let’s start by building from scratch!

Most of these examples are also in general_quarto.qmd (so you can reference that file later if you want to see how something should look)

install.packages("rmarkdown")

Make a new file and select “Quarto Document”

Editing

Quarto documents have two different view/edit options in RStudio:

Markdown

  • Make some headers, format some text
  • Including images, links
  • Comments are html-style, written <!-- this is a comment --> rather than the usual # we expect in R
  • You can include html
  • Divs and div options (.sidebar, .warning, .callout-note/tip/caution/etc, )
  • Equations
  • Lots and lots more things you can make—diagrams, tables, etc! More info here

Example

Test

Note

Hello there!

This one has a title!

There are five kinds of these: note, tip, caution, warning, important

You can also make them collapsible, etc.

No level of lead exposure is considered safe

For more information about lead in drinking water, visit https://www.washtenaw.org/1811/Lead. (Just a made up example heading)

Code

  • Code chunks
  • Chunk options: echo, eval, include, error, warnings, echo:fenced (full list here)
  • Let’s make a ggplot!
  • Let’s also make a table!

Other kinds of code: flowchart example

```{mermaid}
flowchart LR
  A[Hard edge] --> B(Round edge)
  B --> C{Decision}
  C --> D[Result one]
  C --> E[Result two]
```
flowchart LR
  A[Hard edge] --> B(Round edge)
  B --> C{Decision}
  C --> D[Result one]
  C --> E[Result two]

YAML options

  • types of output: html, revealjs, pptx, docx, pdf, plus dashboard (coming soon)
  • title, author, date
  • table of contents
  • figure sizes
  • most of the code chunk options can also go here if you want them to be global

Word and powerpoint themes

  • try with example theme files
  • In general, need the theme file to include examples of all the headings/slide types/etc.

Template example

Dashboards note

In the pre-release of Quarto 1.4: https://quarto.org/docs/dashboards/

In the meantime: flexdashboard with Rmarkdown

Notes to self

Stuff to cover

  • basic document making
  • quick intro to markdown
    • including images (locally and from a web address with html here
    • you can include html!
    • why are comments different in the markdown parts than in the code? Isn’t the # symbol supposed to mean comment?
  • quick intro to code, chunk options, etc.
    • make some ggplots and tables
  • come back to yaml
    • try out writing a doc to different formats and see what it does
    • different figure sizes
    • code fold
    • many of the code chunk options can also go here if you want them to be global
  • some quick interactive things—plotly, leaflet
  • should we talk about hosting?
  • briefly mention shiny but more on that later