Activity 4.5 — 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

July 5, 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

Download the template report → leaf_report_template.qmd

Save it into your project’s documents/ folder. It already has the YAML, the library chunk, a summary table, and a figure. You will study it in Step 6 and use it as a safety net if you fall behind.

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 — the exact t-test from Worksheet 04, written up as a Quarto report. The t-statistic, p-value, and group means are dropped straight into the sentences with inline code, and it renders to a clean Word document. That is the payoff of everything in this activity: the analysis you already ran becomes a report that writes its own numbers. Notice you would never copy a single value by hand.

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 weight 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)

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

#| label: load-data
tree_df <- read_excel("data/2026_06_25_tree_experiment_raw_data.xlsx")

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 result and drop it into a sentence

Add a chunk that calculates the group means:

#| label: means
summary_df <- tree_df %>%
  group_by(side) %>%
  summarize(mean_wt = round(mean(weight_g, na.rm = TRUE), 2))

mean_shady <- summary_df$mean_wt[summary_df$side == "shady"]

Then, in your text, use inline code to insert the number automatically:

Shady-side leaves averaged `r mean_shady` g.

Render. The real number appears in the sentence — and 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.


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