7: Quarto & Reproducibility
Content for Monday, April 20, 2026
Before class
📖 Reading:
During class
We’ll cover:
- What is literate programming? Code + narrative in one document
- Why reproducibility matters
- Quarto basics: YAML header, Markdown text, code chunks
- Code chunk options:
echo,eval,include,message,warning - Figure options:
fig-width,fig-height,fig-cap - Inline code — embedding results in text (never hard-code statistics!)
- Output formats: HTML, PDF, Word
- Tables with
knitr::kable()
TipAssignment 3 is assigned today
Assignment 3: Tidying, Import & Quarto — due Sunday, April 26 at 11:59 PM.
Slides
View slides in new tab Download PDFEmbedded slides
After class
✅ Practice:
- Create a new Quarto document (
.qmd). Add a title, your name, and today’s date in the YAML header - Write a short introduction in Markdown — use headers, bold, italic, and a bulleted list
- Add a code chunk that loads a dataset and creates a plot. Try
#| echo: falseto hide the code - Use inline code to report a summary statistic in a sentence (e.g., “The mean age was
`r knitr::inline_expr("mean(data$age)")`”) - Render your document to HTML. Then try PDF (you may need to install
tinytex)
NoteThe golden rule of reproducibility
Never hard-code a number in your text. If your data changes, your text should update automatically.
Instead of: > “The mean score was 4.2.”
Write: > “The mean score was `r knitr::inline_expr("round(mean(data$score, na.rm = TRUE), 1)")`.”
This way, if you add more data or fix an error, everything stays in sync.
Useful chunk options
#| label: fig-results
#| echo: false
#| fig-cap: "Mean anxiety scores by condition"
#| fig-width: 8
#| fig-height: 5
ggplot(data, aes(x = condition, y = anxiety)) +
stat_summary(fun = mean, geom = "bar") +
stat_summary(fun.data = mean_se, geom = "errorbar", width = 0.2)