Code
treasure <- read.csv("data/treasure_hunt.csv")
n_teams <- nrow(treasure)
top_score <- max(treasure$final_treasure)
top_major <- treasure$major[which.max(treasure$final_treasure)]~13 minutes Β· The map that unlocks the rest
Instructor Β· Stage 1 (~13 min). Have the .qmd source on the left and the rendered HTML on the right in RStudio. Narrate each section as you scroll through both. Students follow on screen β no R required to observe.
Learn the building blocks of any .qmd file so you can read β and write β any Quarto document.
.qmd file?A Quarto Markdown file mixes three things in one document:
--- dashes)When you click Render (or run quarto render), Quarto executes the code, weaves output into prose, and produces polished HTML, PDF, or a slide deck β or all three from the same file.

Think of it as the treasure map legend β it tells Quarto what to produce.
---
title: "My Report"
format:
html:
theme: cosmo
toc: true
code-fold: show
execute:
echo: true
warning: false
---| Key | What it does |
|---|---|
format: html |
Output as a web page (also pdf, docx, revealjs) |
toc: true |
Auto table of contents |
code-fold: show |
Show code with a collapse button |
echo: false |
Hide code, keep output β great for client reports |
theme: cosmo |
One word changes the whole visual design |
Change cosmo to darkly or journal and re-render. The entire document reskins in seconds.
Everything outside a code chunk is plain Markdown:
## A heading
Normal text. **Bold**, *italic*, `inline code`.
- Bullet one
- Bullet two
> A blockquote for emphasis
One of Quartoβs most powerful features is embedding live R values directly in prose:
Write this sentence in your document:
βThe dataset contains 25 teams. The highest score was 99, achieved by a student in OMIS.β
When the data updates, the sentence updates. No copyβpaste. No drift.
π΄ββ οΈ Fragment #1: The command that turns a raw .qmd into a finished document is render.
Code chunks are enclosed in triple backticks with {r}. Each chunk can have options set with #|:
# A tibble: 1 Γ 4
n_teams avg_score avg_clues fastest_min
<int> <dbl> <dbl> <dbl>
1 25 80.7 6.8 40
| Chunk option | Effect |
|---|---|
#| echo: false |
Hide code, show only output |
#| eval: false |
Show code, do NOT run it |
#| fig-width: 8 |
Control plot width |
#| fig-cap: "..." |
Add a figure caption |
Note β contextual information worth knowing
Tip β best practices and suggestions
Warning β something the reader must watch out for
Important β must-read information
Use when you want analysis, evidence, and polished prose in one reproducible file.
Use when you want to present results without rebuilding everything in another app.
Use when you have multiple pages, navigation, or a project portfolio to share.
You know the four building blocks of every Quarto document: YAML Β· Markdown Β· Inline R Β· Code chunks
Continue to π Stage 2: Analysis

---
title: "π§ Stage 1 Β· Quarto + RStudio Field Guide"
subtitle: "~13 minutes Β· The map that unlocks the rest"
format:
html:
toc: true
code-fold: show
execute:
echo: true
warning: false
message: false
---
::: {.instructor-note}
**Instructor Β· Stage 1 (~13 min).** Have the `.qmd` source on the left and the rendered HTML on the right in RStudio. Narrate each section as you scroll through both. Students follow on screen β no R required to observe.
:::
<div class="hero-banner">
<h1>π Stage 1 Β· Decode the Map</h1>
<p>Learn the building blocks of any <code>.qmd</code> file so you can read β and write β any Quarto document.</p>
</div>
::: columns
::: {.column width="66%"}
## What is a `.qmd` file?
A Quarto Markdown file mixes **three things** in one document:
1. **YAML header** β configuration at the very top (between `---` dashes)
2. **Markdown prose** β your narrative, headings, lists, images
3. **R code chunks** β live code that runs and embeds output automatically
When you click **Render** (or run `quarto render`), Quarto executes the code, weaves output into prose, and produces polished HTML, PDF, or a slide deck β or all three from the same file.
:::
::: {.column width="32%"}
<img src="https://media.giphy.com/media/HVcPS8srK742xYwVav/giphy.gif"
alt="Pirate coding gif"
class="gif-center">
:::
:::
---
## <span class="step-counter">1</span> The YAML header
Think of it as the **treasure map legend** β it tells Quarto what to produce.
```yaml
---
title: "My Report"
format:
html:
theme: cosmo
toc: true
code-fold: show
execute:
echo: true
warning: false
---
```
| Key | What it does |
|---|---|
| `format: html` | Output as a web page (also `pdf`, `docx`, `revealjs`) |
| `toc: true` | Auto table of contents |
| `code-fold: show` | Show code with a collapse button |
| `echo: false` | Hide code, keep output β great for client reports |
| `theme: cosmo` | One word changes the whole visual design |
::: {.callout-tip}
## Live experiment
Change `cosmo` to `darkly` or `journal` and re-render. The entire document reskins in seconds.
:::
---
## <span class="step-counter">2</span> Markdown prose
Everything outside a code chunk is plain Markdown:
```markdown
## A heading
Normal text. **Bold**, *italic*, `inline code`.
- Bullet one
- Bullet two
> A blockquote for emphasis

```
---
## <span class="step-counter">3</span> Inline R β numbers that never drift
One of Quarto's most powerful features is embedding live R values directly in prose:
```{r}
treasure <- read.csv("data/treasure_hunt.csv")
n_teams <- nrow(treasure)
top_score <- max(treasure$final_treasure)
top_major <- treasure$major[which.max(treasure$final_treasure)]
```
Write this sentence in your document:
> *"The dataset contains `r n_teams` teams. The highest score was `r top_score`, achieved by a student in `r top_major`."*
When the data updates, the sentence updates. **No copyβpaste. No drift.**
<div class="clue-box">
π΄ββ οΈ <strong>Fragment #1:</strong> The command that turns a raw <code>.qmd</code> into a finished document is <strong>render</strong>.
</div>
---
## <span class="step-counter">4</span> Code chunks
Code chunks are enclosed in triple backticks with `{r}`. Each chunk can have options set with `#|`:
```{r}
library(tidyverse)
treasure <- read_csv("data/treasure_hunt.csv", show_col_types = FALSE)
treasure |>
summarise(
n_teams = n(),
avg_score = round(mean(final_treasure), 1),
avg_clues = round(mean(clues_solved), 1),
fastest_min = min(time_minutes)
)
```
| Chunk option | Effect |
|---|---|
| `#| echo: false` | Hide code, show only output |
| `#| eval: false` | Show code, do NOT run it |
| `#| fig-width: 8` | Control plot width |
| `#| fig-cap: "..."` | Add a figure caption |
---
## <span class="step-counter">5</span> Callouts β four types
::: {.callout-note}
**Note** β contextual information worth knowing
:::
::: {.callout-tip}
**Tip** β best practices and suggestions
:::
::: {.callout-warning}
**Warning** β something the reader must watch out for
:::
::: {.callout-important}
**Important** β must-read information
:::
---
## <span class="step-counter">6</span> Panel tabs β multiple views, one block
:::: {.panel-tabset}
### π Report
Use when you want analysis, evidence, and polished prose in one reproducible file.
### π½οΈ Slides
Use when you want to present results without rebuilding everything in another app.
### π Website
Use when you have multiple pages, navigation, or a project portfolio to share.
::::
---
## Stage 1 complete β
You know the **four building blocks** of every Quarto document:
YAML Β· Markdown Β· Inline R Β· Code chunks
Continue to **[π Stage 2: Analysis](report.qmd)**
<img src="https://media4.giphy.com/media/v1.Y2lkPTc5MGI3NjExODV5NDVhc3NrcjNoYTdlbjc0dm9mZnVwMG5mczJxN3B1azJ1N2wyNSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/1Ctu1BCYf21we9tRmT/giphy.gif"
alt="Pirate coding gif"
class="gif-center">