name <- "Maureen"
age <- 42
today <- Sys.Date()
halloween <- as.Date("2026-10-31")Data Skills for Psychology — Module 2
These slides are adapted from Applied Data Skills Ch. 2.
By the end of this class, you will be able to:
Reproducibility means that others (and future you) can understand and check your work.
Think-Pair-Share
Hint: Think about the replication crisis…
Now let’s put reproducibility into practice.
Imagine you need to produce a monthly analytics report. You could:
Projects in RStudio group all the files you need for one piece of work: scripts, data, images, and outputs.
Without projects:
With projects:
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
Do this now!
dataskills-26 (no spaces!)dataskills-26 folderFollow along!
Week01dataskills-26 folderCheck the Files tab — you should see Week01.Rproj
Warning
Never save a project inside another project folder!
Good file names make life easier for both humans and computers.
report.docreport final.docData (Nov 15).xlsfinal report2.docreport_v1.docreport_v2.docdata_customer_2021-11-15.xls_project-notes.txt-, and underscores __ to separate parts, - to separate wordsDiscussion
Look at some files on your own computer. What would you rename?
Quarto lets you combine text and code in one document to create reproducible reports.
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.
Follow along!
Reports02-reports.qmdAt the top of every Quarto document is a YAML header between triple dashes:
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.
RStudio has two editing modes:
Note
The examples in the textbook use the source editor, so we’ll stick with that for consistency.
| What you type | What you get |
|---|---|
**bold** |
bold |
*italic* |
italic |
~~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.
A code chunk is where you put your R code inside a Quarto document.
Keyboard shortcut: Cmd/Ctrl + Enter (one line) or Cmd/Ctrl + Shift + Enter (whole chunk)
Green play button: Click the ▶ at the top-right of the chunk
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!
Most Quarto documents should start with a setup chunk that loads packages:
label: setup names this as the setup chunkinclude: false means this chunk won’t appear in the rendered documentlibrary() calls deep in your scriptInline code lets you insert R values directly into your text — no more copy-pasting results!
And Quarto renders:
My name is Maureen and I am 42 years old.
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?
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!
We can load data from a URL or a local file using read_csv():
Note
/ (even on Windows!)Step by step
data folder inside your projectCompare
head, summary, str, View) tell you that the others don’t?A report in Quarto weaves narrative and analysis together:
The $ sign accesses a column: group_counts$n
Square brackets pick a specific value: $n[1] = first value
Use # to add explanatory notes inside code chunks:
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!
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.
When you render, the plot appears right in your report!
Use Markdown syntax to embed images:
Note
Always add alt text for accessibility: {fig-alt="Description of image"}
The simplest way to display data as a table — just print the object:
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.
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.
By default, rendered HTML files need a companion _files folder. To make a single, self-contained file:
This is essential when you want to email or submit your report as one file!
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.
📖 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?