Quarto Reports

Data Skills for Psychology — Module 2

Welcome Back!

These slides are adapted from Applied Data Skills Ch. 2.

Today’s Goals

By the end of this class, you will be able to:

  • Structure a project in RStudio
  • Render a simple reproducible report with Quarto
  • Create code chunks, tables, images, and inline R
  • Customize your report with YAML options

Reproducibility

Why Reproducibility Matters

Reproducibility means that others (and future you) can understand and check your work.

Without reproducibility

  • “I clicked some buttons…”
  • “I think I deleted those rows…”
  • “It worked on my computer…”

With reproducibility

  • Code documents every step
  • Anyone can re-run your analysis
  • Results are verifiable

Discussion: Reproducibility in Psychology

Think-Pair-Share

  1. Think: Why might reproducibility be especially important in psychology research?
  2. Pair: Discuss with your neighbor for 1 minute
  3. Share: What did you come up with?

Hint: Think about the replication crisis…

Why Reproducible Reports?

Now let’s put reproducibility into practice.

Imagine you need to produce a monthly analytics report. You could:

The old way

  1. Run analysis in R
  2. Copy results into Word
  3. Format tables by hand
  4. Paste in plots
  5. Repeat every month

The Quarto way

  1. Write code + text together
  2. Click Render
  3. Done!
  4. New data? Render again.

Projects

Why Use Projects?

Projects in RStudio group all the files you need for one piece of work: scripts, data, images, and outputs.

Without projects:

  • Files scattered everywhere
  • Broken file paths
  • “It works on my computer…”

With projects:

  • Everything in one folder
  • Relative paths just work
  • Easy to share and reproduce

The File System

Your computer stores files in a hierarchy of directories (folders).

A file path describes where a file lives:

/Users/maureenritchey/Documents/dataskills-26/data/mydata.csv

The ~ shortcut represents your home directory:

~/Documents/dataskills-26/data/mydata.csv

Activity: Set Up Your R Projects Folder

Do this now!

  1. Create a new folder on your computer called dataskills-26 (no spaces!)
  2. Put it somewhere easy to find (Desktop, Documents, or a cloud drive)
  3. In RStudio: Tools > Global Options > General
  4. Set “Default working directory” to your new dataskills-26 folder

Activity: Create a New Project

Follow along!

  1. File > New Project…
  2. Select New Directory > New Project
  3. Name it Week01
  4. Save it inside your dataskills-26 folder
  5. Click Create Project

Check the Files tab — you should see Week01.Rproj

Warning

Never save a project inside another project folder!

Naming Things Well

Good file names make life easier for both humans and computers.

Bad names

  • report.doc
  • report final.doc
  • Data (Nov 15).xls
  • final report2.doc

Good names

  • report_v1.doc
  • report_v2.doc
  • data_customer_2021-11-15.xls
  • _project-notes.txt

Naming Rules

  • Only letters, numbers, dashes -, and underscores _
  • No spaces!
  • Be consistent with capitalization (lowercase is easiest)
  • Use _ to separate parts, - to separate words
  • Use numbers to control sort order

Discussion

Look at some files on your own computer. What would you rename?

Quarto

What is Quarto?

Quarto lets you combine text and code in one document to create reproducible reports.

  • Text is written in Markdown (simple formatting syntax)
  • Code goes in code chunks (grey boxes)
  • Output can be HTML, PDF, Word, slides, and more!

Note

If you’ve used R Markdown before, Quarto is basically a newer, more powerful version. The syntax is very similar — you can even rename .Rmd files to .qmd and they’ll usually work.

Activity: Create Your First Quarto Document

Follow along!

  1. File > New File > Quarto Document…
  2. Title it Reports
  3. Keep the output format as HTML
  4. Click Create
  5. Save the file as 02-reports.qmd

The YAML Header

At the top of every Quarto document is a YAML header between triple dashes:

---
title: "Reports"
author: "Maureen Ritchey"
date: 2026-04-01
format: html
---

This tells Quarto how to build your document — title, author, output format, and more.

Warning

YAML is very picky about spacing and indentation! Watch those spaces carefully.

Source vs. Visual Editor

RStudio has two editing modes:

Source Editor

  • See the raw Markdown
  • Hashes, asterisks, backticks visible
  • More control
  • We’ll use this one

Visual Editor

  • Looks like Word
  • WYSIWYG formatting
  • Easier for beginners
  • Toggle at top of source pane

Note

The examples in the textbook use the source editor, so we’ll stick with that for consistency.

Markdown

Basic Markdown Syntax

## This is a Header

This is a paragraph. Leave blank lines between paragraphs.

* bullet point one
* bullet point two

1. numbered item
2. another item

[link text](https://example.com)

Activity: Write Some Markdown

Replace the template text with this:

## Basic Markdown

Now I can make:

* headers
* paragraphs
* lists
* [links](https://psyteachr.github.io/ads-v3/)

Try rendering your document (Render button) to see how it looks!

Text Formatting

What you type What you get
**bold** bold
*italic* italic
~~strikethrough~~ strikethrough
`code` code
H~2~O H2O
x^2^ x2

Try it!

Add a few of these to your document and render to see the result.

Code Chunks

What is a Code Chunk?

A code chunk is where you put your R code inside a Quarto document.

```{r}
# this is a code chunk
name <- "Maureen"
age <- 42
```
  • Everything between the triple backticks is treated as code
  • Everything outside is treated as text
  • On most themes, code chunks appear with a grey background

Activity: Add a Code Chunk

Add this to your document

Create a new code chunk with the objects from last week:

name <- "Maureen"
age <- 42
today <- Sys.Date()
halloween <- as.Date("2026-10-31")

Run it using Cmd/Ctrl + Shift + Enter (runs the whole chunk)

Running Code — Three Ways

  1. Keyboard shortcut: Cmd/Ctrl + Enter (one line) or Cmd/Ctrl + Shift + Enter (whole chunk)

  2. Green play button: Click the ▶ at the top-right of the chunk

  3. Menu: Run > Run Selected Line(s)

Quick poll

Which method do you find most convenient? The keyboard shortcut is worth learning — it’ll save a lot of time!

The Setup Chunk

Most Quarto documents should start with a setup chunk that loads packages:

```{r}
#| label: setup
#| include: false

library(tidyverse)
```
  • label: setup names this as the setup chunk
  • include: false means this chunk won’t appear in the rendered document
  • Always load packages here — don’t bury library() calls deep in your script

Inline Code

What is Inline Code?

Inline code lets you insert R values directly into your text — no more copy-pasting results!

You write:

My name is `r name` and I am `r age` years old.

And Quarto renders:

My name is Maureen and I am 42 years old.

Activity: Try Inline Code

Add this text below your code chunk

My name is `r name` and I am `r age` years old.
It is `r halloween - today` days until Halloween.

Render the document. The code should be replaced with actual values!

Order matters!

The code chunk that creates the objects must come before the inline code that uses them. Try moving the code chunk below the text — what happens when you render?

Discussion: Why Inline Code Matters

Think about this

You run a study with 247 participants. You write in your paper:

“Our sample consisted of 247 participants.”

Then you clean the data and drop 12 people. Now what?

. . .

With inline code, writing this in your text automatically updates the number!

Our sample consisted of `r nrow(clean_data)` participants.

Loading Data

Reading in Data

We can load data from a URL or a local file using read_csv():

# From a URL
smalldata <- read_csv("https://psyteachr.github.io/ads-v3/data/smalldata.csv")

# From a local file
smalldata <- read_csv("data/smalldata.csv")

Note

  • The file path must be in quotes
  • Use forward slashes / (even on Windows!)
  • Use tab auto-complete inside quotes to avoid typos

Activity: Load and Explore Data

Step by step

  1. Create a data folder inside your project
  2. Download smalldata.csv and save it there
  3. Add a code chunk to load the data:
smalldata <- read_csv("data/smalldata.csv")
  1. Explore the data — try each of these in the console:
head(smalldata)
summary(smalldata)
str(smalldata)
View(smalldata)

Activity: Discuss What You Found

Compare

  • How many rows and columns does the data have?
  • What are the variable names?
  • What does each function (head, summary, str, View) tell you that the others don’t?

Writing Your Report

Combining Code and Text

A report in Quarto weaves narrative and analysis together:

## Data Analysis

```{r}
group_counts <- count(smalldata, group)
```

The control group had `r group_counts$n[1]` participants.

The $ sign accesses a column: group_counts$n

Square brackets pick a specific value: $n[1] = first value

Activity: Build Your Analysis Section

Add to your report

  1. Create a heading “Data Analysis”
  2. Add a code chunk:
group_counts <- count(smalldata, group)
  1. Below the chunk, add this text:
The total number of participants in the **control**
condition was `r group_counts$n[1]`.
  1. Add a similar line for the experimental condition
  2. Render and check!

Code Comments

Use # to add explanatory notes inside code chunks:

# Calculate key statistics
n <- nrow(smalldata)            # total participants
mean_pre <- mean(smalldata$pre)  # mean pre-test score
mean_post <- mean(smalldata$post) # mean post-test score

Pro tip

If you name objects clearly (mean_pre instead of x), you need fewer comments. But when you’re learning, comment everything — it helps solidify your understanding!

Images & Tables

Adding Plots from Code

You can generate plots directly in your document. We will go over this in detail in a few weeks, but here is a quick copy-and-paste example.

ggplot(data = smalldata,
       mapping = aes(x = pre,
                     y = post,
                     color = group)) +
  geom_point() +
  labs(x = "Pre-test Score",
       y = "Post-test Score")

When you render, the plot appears right in your report!

Adding External Images

Use Markdown syntax to embed images:

![Caption text](path/to/image.png){width="300px"}

Or from a URL:

![ADS Logo](https://psyteachr.github.io/images/ads.png){width="200px"}

Note

Always add alt text for accessibility: {fig-alt="Description of image"}

Tables

The simplest way to display data as a table — just print the object:

smalldata

Make it look nicer by adding to your YAML header:

format:
  html:
    df-print: kable

Refining Your Report

Execution Options (YAML)

Control default behavior for all code chunks in the YAML header:

---
execute:
  echo: false       # hide code in output
  message: false    # hide messages
  warning: false    # hide warnings
  fig-width: 8      # figure width (inches)
  fig-height: 5     # figure height (inches)
---

Try it!

Add these to your YAML, then toggle echo between true and false. Render each time to see the difference.

Themes and Appearance

---
format:
  html:
    theme: cosmo
    toc: true
    toc-depth: 3
---

Built-in themes include: default, cerulean, cosmo, darkly, flatly, journal, lumen, sandstone, simplex, united, yeti, and more!

Activity

Try changing your theme — pick one you like! Browse options at bootswatch.com.

Embedding Resources

By default, rendered HTML files need a companion _files folder. To make a single, self-contained file:

---
format:
  html:
    embed-resources: true
---

This is essential when you want to email or submit your report as one file!

Output Formats

Quarto can render to many formats:

Format YAML value
HTML webpage html
PDF document pdf
Word document docx
PowerPoint pptx
Reveal.js slides revealjs

Note

In this class, we will default to using HTML for our output format.

Wrapping Up

Key Takeaways

  • Projects keep your work organized with relative file paths
  • Quarto combines text (Markdown) and code (R) in one document
  • Code chunks run R code; inline code inserts values into text
  • The YAML header controls document settings and appearance
  • Render to produce HTML, PDF, Word, and more
  • Name your files well — no spaces, be consistent!

Before Next Time

📖 Read: Chapter 2 of Applied Data Skills (to solidify today’s material)

✍️ Assignment: Create the demo_report project following the instructions on the Module page.

❓ Questions?