Reproducible Reporting with Quarto

Example 1.1: # Markdown Syntax

In Markdown syntax, you can do the following and more.

  • Headings: # My title, ## My subtitle, ### My subsubtitle
  • Unordered lists:
    • - item 1
    • - item 2
  • Ordered lists:
    • 1. item 1
    • 2. item 2
  • Font: *italic*, **bold**, `monospaced`
  • Links: [text](url)
  • Cross-references: @chunk-label

Example 1.2: Running Code

Add code chunks with alt + cmd + i and click Render to generate a report with both text and code output.

# R code
citation("mia")
To cite package 'mia' in publications use:

  Ernst F, Shetty S, Borman T, Lahti L (2024). _mia: Microbiome
  analysis_. R package version 1.13.26,
  <https://github.com/microbiome/mia>.

A BibTeX entry for LaTeX users is

  @Manual{,
    title = {mia: Microbiome analysis},
    author = {Felix G.M. Ernst and Sudarshan A. Shetty and Tuomas Borman and Leo Lahti},
    year = {2024},
    note = {R package version 1.13.26},
    url = {https://github.com/microbiome/mia},
  }

Exercise 1

Example 2.1: knitr options

You can add options to code chunks to change their behaviour.

  • Original chunk
print("I love my microbiome")
[1] "I love my microbiome"
  • After adding #| echo: false
[1] "I love my microbiome"
  • After adding #| eval: false
print("I love my microbiome")
  • After adding #| code-fold: true
Show code
print("I love my microbiome")
[1] "I love my microbiome"
  • After adding #| include: false

Example 2.2: More about knitr options

If you want an option to affect all chunks in a script, you can set it globally.

# Turn off chunk visibility and warnings
knitr::opts_chunk$set(echo = FALSE, warning = FALSE)

You can label figures (or tables) with #| label: fig-name and cross-reference them with @fig-name (Figure 1).

data(iris)
boxplot(Sepal.Length ~ Species, data = iris)

Figure 1: A boxplot of the sepal length distribution by species.

Example 2.3: YAML Parameters

At the beginning of any Quarto document, there is a box delimited by ---. There you can define document metadata, such as title, author, date, output format, bibliography, citation style, theme, font size and many others.

---

title: “Around the gut in 24 hours”

format: html

editor: visual

smaller: true

author: Escherichia coli

date: 2024-07-08

---

Exercise 2

Extra:

Resources