Activity 07 — Build Your First Quarto Report

Turn your leaf analysis into a professional Word document

quarto
reproducibility
markdown

Follow-along activity paralleling the Quarto lecture. Students create a .qmd file, add YAML, Markdown, and named code chunks, and render the leaf analysis to a Word document using the provided template.

Author

Bill Perry

Published

September 10, 2026

Before you start

This activity parallels the lecture. Go slowly — you do not need to type fast. Each step is small, and there is a finished template you can lean on.

Tip📥 Download the template and the data
Note👀 See a finished report first — why we bother

Before you build your own, open this worked example and render it:

t_test_report.qmd — a preview of the t-test you’ll run in Activities 09–10, already written up as a Quarto report. The t-statistic, p-value, and group means are computed into the tables directly from the data, and it renders to a clean Word document. That is the payoff of everything in this activity: an analysis becomes a report that writes its own numbers — and reports them honestly, whether or not the test is significant. Notice you would never copy a single value by hand — and in a few weeks, this will be your analysis.

What you need open: Positron, your class project folder (data/, documents/, figures/, scripts/), and your leaf data in data/.


Step 1 · Make a new Quarto document

In Positron: File → New File → Quarto Document. Save it right away into your documents/ folder as my_leaf_report.qmd.

Note

A .qmd file is just plain text. You can open it anywhere, and it lives happily inside your project like your scripts do.


Step 2 · Write the YAML front matter

At the very top of the file, type this between two lines of three dashes. Use spaces, never tabs, for the indenting.

---
title: "Leaf Morphology Report"
author: "Your Name"
date: today
format: docx
---

Press Render (Ctrl/Cmd + Shift + K). A blank-ish Word document should open with your title on it. 🎉 You just made a Word file from plain text.

Warning

If Render fails, check that both --- lines are alone on their own line and that your indenting is spaces.


Step 3 · Add some Markdown text

Below the YAML, write a few lines using Markdown symbols:

# Introduction

We measured leaf mass on the **sunny** and **shady** sides of a tree.

- Null hypothesis: no difference between sides
- Alternate hypothesis: sides differ

Render again. Notice the # became a real heading and the - became bullets.


Step 4 · Add a code chunk (and name it)

Insert a chunk with Ctrl/Cmd + Alt + I, then make it load your packages and data. Give it a short name after r:

#| label: libraries
library(readxl)
library(tidyverse)
library(janitor)

Add a second, uniquely named chunk to read your data:

#| label: load-data
leaf_df <- read_excel("data/2026_09_03_data_sci_leaf_area.xlsx") |>
  clean_names()

Render. If it breaks, the message names the chunk — go straight to it.

Tip

Same habit as your scripts: small, uniquely named chunks make errors easy to find. No two chunks can share a name.


Step 5 · Compute a summary and print it into the report

Add a chunk that calculates the group means and prints the result:

#| label: means
summary_df <- leaf_df %>%
  group_by(shade) %>%
  summarize(mean_mass = round(mean(mass_g, na.rm = TRUE), 3))

summary_df

Then, in your text, refer to the value straight from the printed table:

Read the mean mass for each side from the `mean_mass` column of the table above.
Because the table is built from the data every render, it updates itself when the
data changes — you never retype a number.

Render. The number in your report always matches the data — because you never typed it.


Step 6 · Make it look professional

Now upgrade your YAML to match the downloaded template so the report gets a table of contents and numbered sections:

format:
  docx:
    toc: true
    number-sections: true
    fig-width: 6
    fig-height: 4
    fig-format: png

Open leaf_report_template.qmd side by side. Copy in its summary-table and leaf-plot chunks so your report has a real table and figure. Render.

Note

Set echo: false in the execute: block (top of the file) to hide the code so your report shows only results — the way a reader wants it.


Step 7 · One file, three outputs (optional)

Change your format: block to build a Word file, a web page, and slides — all from the same analysis:

format:
  docx: default
  html: default
  pptx: default

Render. Three documents, zero extra work.


Check yourself

You are done when you can:

  • Render your .qmd to a Word document with a title, TOC, and numbered sections
  • Show a summary table and a figure computed from your data
  • Point to one number in a sentence that came from inline code
  • Explain why you would never copy those numbers by hand again
Tip🖐 Stuck or behind?

Open leaf_report_template.qmd, render it as-is to confirm your setup works, then compare it to your file chunk by chunk. For a fuller example with a real statistical test, study t_test_report.qmd.


Extension — out of class (~30–40 min)

Turn this in in the same .qmd you built in class. This adds Quarto features you have not seen yet — cross-references and callouts. Put your written answers in the report prose (or in <!-- comments -->) right where they belong.

E1 · Cross-reference your table and figure (4 pts)

Quarto can number your table and figure and let your prose refer to them by number automatically, so it stays correct even if you reorder things.

  1. Give your table chunk #| label: tbl-summary and #| tbl-cap: "...".
  2. Give your figure chunk #| label: fig-leaf and #| fig-cap: "...".
  3. In your Results prose, write @tbl-summary and @fig-leaf instead of “the table above” / “the figure below”. Render and check the numbers appear.
  4. Add one callout of your own (::: callout-note/-warning/-tip) flagging a real limitation of your analysis (small n, an outlier you kept, an assumption you’re unsure of) — not a generic one.

Record the label: lines you added and the exact sentence where you used @tbl-summary or @fig-leaf.

E2 · Predict, then check (3 pts)

Before touching any chunk options: if you added #| echo: false to only the chunk that computes your summary table (not the whole document), what exactly changes in the rendered Word doc, and what stays identical? Be specific about which chunks are affected. Then make the change, render, and write whether you were right.

E3 · Explain it (3 pts)

As if explaining to a classmate who missed this unit:

  1. Point to one chunk in your own report and say why you set echo the way you did for that chunk.
  2. If someone changed one number in your raw data file, walk through exactly what happens the next time you press Render — which chunks rerun, which outputs change, which don’t.
  3. Why is referring to @tbl-summary safer than typing “Table 1” by hand?

Turn it in

Render to Word and submit both:

  1. my_leaf_report.qmd (your source file)
  2. my_leaf_report.docx (the rendered report)

References: 📖 R4DS Ch 28 — Quarto · 📖 R4DS Ch 29 — Formats · 🌐 quarto.org guide