Why Quarto? Code chunks, Markdown, and a professional Word document
2026-07-05
filter(), select(), mutate(), arrange()group_by() + summarize().R scriptNote
✅ Key idea from Lecture 04
You now have a complete analysis and a real result. Today we turn that pile of code into a report a human can read.
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, press Render. Done.

Note
Same philosophy as Lecture 02: never overwrite your raw numbers — let the document rebuild from them.
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’”. Learning to read that message is the whole skill. When it happens to you, you’ll go straight to the repeated name.
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 inline `r ` to drop live numbers into sentences.
Tip
🖐 After this chunk: Activity Step 5 (compute a value and drop it into a sentence).
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: If mean(shady_wt) is 7.8, what exact sentence will render from the inline-code line below? Say it out loud before you check.
Drop a live result into a sentence with `r `:
renders as:
Shady leaves averaged 7.8 g.
Note
✅ Key idea
This is the magic of Quarto: your prose stays true to your data, automatically.
Warning
⚠️ Watch out!
Inline code only works if the object exists. Load and compute it in a chunk above the sentence.
Compute a group mean, then insert it into a sentence with inline code. Predict the number that will appear 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.
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 04 t-test, 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.
Up next — Lecture 06:
lm()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