Why Quarto? Code chunks, Markdown, and a professional Word document
2026-09-10
filter(), select(), mutate(), arrange()group_by() + summarize().R scriptNote
✅ Key idea from Lecture 06
You now have a complete descriptive analysis of the leaf data. Today we turn that pile of code into a report a human can read — before we even get to formal hypothesis testing.
Tip
🖐 Try it yourself
By the end you will click Render and get a finished Word report of our leaf study.
Tools today:
References:
This lecture runs in four short chunks. After each chunk you switch to the activity and build your own report.
For every snippet, do three things:
Note
✅ Why bother? (the evidence)
We will cover: the pain of script-plus-copy-paste, literate programming, and reproducibility — the real payoff.
Tip
🖐 After this chunk: open the finished example t_test_report.qmd, Render it, then start Activity Step 1.
Your .R script is great for running code. But when the lab report is due you have to:
Warning
⚠️ Watch out!
Every hand-copied number is a chance for a typo. Change one data point and the whole report is out of date.
Note
📊 Coming from Excel?
This is the same pain as pasting a chart into Word, then editing the spreadsheet and forgetting to update the chart.
Literate programming — write the story and the code in the same file.
Note
📖 New word
Quarto = the tool that turns one plain-text .qmd file into a polished document.
Note
✅ Key idea
A script does the analysis.
A Quarto document does the analysis and explains it — and rebuilds itself on demand.
Change your data file, press Render, and:
This is what scientists mean by reproducible — anyone (including future-you) can regenerate your exact results.
Tip
🖐 Try it yourself
Imagine a reviewer finds one bad leaf measurement. With Quarto the fix is: delete the row, then press Render — every table, figure, and sentence downstream updates to match.

Note
Same philosophy as Lecture 02: never overwrite your raw numbers — let the document rebuild from them.
🛑 Do Activity Step 1 now
Open t_test_report.qmd, press Render, and watch a script become a finished Word report. Then make your own new .qmd (Step 1).
.qmdWe will cover: the three ingredients — YAML front matter, Markdown text, and named code chunks.
Tip
🖐 After this chunk: Activity Steps 2–4 (write the YAML, add Markdown, add named chunks).
.qmd fileEvery Quarto document has the same three ingredients:
You already read these every day — this whole lecture is a .qmd file.
Note
📖 New word
.qmd = a Quarto markdown file. Plain text you can open anywhere.
Note
✅ Key idea
If you can write a script and write an email, you already know two of the three parts. Only the YAML is new.
The block at the very top, fenced by three dashes ---. It is the recipe — what to build and how:
title, author, date — appear at the top of the reportformat: docx — make a Word documentWarning
⚠️ Watch out!
YAML is space-sensitive. Indent with spaces, never tabs. A stray space is the #1 beginner error.
Note
📖 New word
YAML = “YAML Ain’t Markup Language.” Just a tidy list of key: value settings.
format: is the only line you change to get Word vs. HTML vs. PowerPoint.
Note
🔮 Predict first: Look at the Markdown block below. Before it renders, sketch what it becomes — which line is a big heading, which are bullets, what turns bold?
Markdown is formatting with symbols instead of toolbar buttons:
You write the symbols; Quarto turns them into real headings, bullets, and links.
Note
📖 New word
Markdown = a simple way to format plain text using a few symbols like #, *, and -.
Note
📊 Coming from Word?
**bold** is just the keyboard version of clicking the B button. Same result, no mouse.
Note
🔮 Predict first: The chunk below runs mean(c(4, 3, 5, 7)). What number will land in the document? Predict before you look.
A code chunk is a fenced block of R that actually runs when you render:
```{r} — the {r} means “this is R”```Tip
Shortcut to insert a chunk: Ctrl/Cmd + Alt + I
Note
✅ Key idea
This is why we write code chunks: the result you see in the report is computed live, so it can never disagree with your code.
Give each chunk a short label after r:
Warning
⚠️ Watch out!
Chunk labels must be unique — no two chunks named plot. Same rule as never overwriting a _plot object.
Note
✅ Key idea
Small, named chunks = easy to find the one line that failed. This is the same debugging strategy from your scripts.
I’ll give two chunks the same label and Render:
… the same label again …
Quarto stops:
ERROR: Duplicate chunk label 'plot'
The fix — make every label unique: plot-box and plot-mean-se.
Tip
✅ Why show a broken render?
Quarto names the exact problem — “Duplicate chunk label ‘plot’”. Once you know to read the error for the chunk name, you’ll go straight to the repeated label instead of guessing.
🛑 Do Activity Steps 2–4 now
Type the YAML by hand (spaces, not tabs), add a heading and bullets in Markdown, and create two uniquely named chunks. Predict what each renders before you press Render.
We will cover: #| options to control what shows, and printing a computed table so the report always matches the data.
Tip
🖐 After this chunk: Activity Step 5 (compute a summary and print it into the report).
Lines starting with #| are chunk options:
| Option | Effect |
|---|---|
echo: false |
hide the code, keep the output |
warning: false |
hide warning messages |
message: false |
hide package startup messages |
eval: false |
show code but do not run it |
Note
✅ Key idea
For a clean report set echo: false — readers see the results, not the code. For a teaching handout, keep echo: true.
Note
🔮 Predict first: The chunk below builds a one-row-per-group summary. How many rows and columns will the printed table have?
Compute the numbers in a chunk and print the result — then refer to it in your prose:
Then, in the text:
Read the mean mass for each side from the
mean_masscolumn of the table above.
Note
✅ Key idea
Keep every number your reader sees inside a chunk’s printed output (a table or a cat() line). Your prose then points at the results instead of restating them.
Warning
⚠️ Watch out!
The chunk that computes the value must run above the text that refers to it — Quarto renders top to bottom.
🛑 Do Activity Step 5 now
Compute a group-means summary in a chunk and print it into the report. Predict the shape of the table before you Render.
We will cover: YAML for a professional Word doc, one file → many outputs, and the render-often workflow.
Tip
🖐 After this chunk: Activity Steps 6–7 (make it professional; one file, three outputs).
.docxThis front matter produces a clean, structured Word document:
Then press Render (or Ctrl/Cmd + Shift + K).
Note
✅ Key idea
toc: true and number-sections: true are what make it look like a report, not a printout.
Tip
🖐 Try it yourself
The activity gives you a ready-made template with exactly this front matter. You just add your writing and render.
The best part: one .qmd, many documents. Just list formats:
All from the same analysis — no re-doing anything.
Note
✅ Key idea
This is exactly how these lecture slides are built. One file → slides, Word, and PowerPoint.
Every time, it is the same three moves:
Quarto runs your code top to bottom in a fresh session — so the order of your chunks matters.
Warning
⚠️ Watch out!
If it renders differently than the console, it is almost always chunk order: load libraries and data first.
Tip
Render often — after every few chunks — so a break is easy to trace. Same as running your script line by line.
🛑 Do Activity Steps 6–7 now
Upgrade the YAML for a TOC and numbered sections, copy in the template’s table and figure, then render to Word, HTML, and PowerPoint.
echo/warning optionsTip
🖐 Before next class
Open the activity template, drop in your Lecture 06 summary statistics, and render it to Word.
Note
✅ Key idea
You turned a script into a reproducible report. From here on, every analysis can be a document that rebuilds itself — including the t-test you’ll run in Lecture 09.
Up next — Lecture 08 (Flex/Catch-up), then Lecture 09:
When Render breaks (it will — that is normal):
library(...) and the data in a chunk above?--- on its own lineNote
✅ Key idea
A Quarto error names the chunk. That is a gift — go straight to that block.
Note
📊 Reference
The Quarto guide is excellent and searchable: quarto.org/docs/guide