Skip to content

Commit 50a6140

Browse files
committed
differences for PR #140
1 parent 640b53a commit 50a6140

3 files changed

Lines changed: 50 additions & 105 deletions

File tree

05-reproducible-reports.md

Lines changed: 49 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,25 @@ exercises: 15
55
source: Rmd
66
---
77

8-
::::::::::::::::::::::::::::::::::::::: objectives
8+
::: objectives
9+
- Describe the value of reproducible reporting.
10+
- Create a new Quarto document (`.qmd`) in RStudio.
11+
- Use Markdown syntax to format text.
12+
- Create and run code chunks within a Quarto document.
13+
- Render a Quarto document to an HTML report.
14+
:::
915

10-
- Describe the value of reproducible reporting.
11-
- Create a new Quarto document (`.qmd`) in RStudio.
12-
- Use Markdown syntax to format text.
13-
- Create and run code chunks within a Quarto document.
14-
- Render a Quarto document to an HTML report.
15-
16-
::::::::::::::::::::::::::::::::::::::::::::::::::
17-
18-
:::::::::::::::::::::::::::::::::::::::: questions
19-
20-
- How can I combine my code, results, and narrative into a single document?
21-
- How can I automatically update my reports when my data changes?
22-
- What is Quarto and how does it differ from a standard R script?
23-
24-
::::::::::::::::::::::::::::::::::::::::::::::::::
16+
::: questions
17+
- How can I combine my code, results, and narrative into a single document?
18+
- How can I automatically update my reports when my data changes?
19+
- What is Quarto and how does it differ from a standard R script?
20+
:::
2521

2622

2723

2824
## Introduction to Reproducible Reporting
2925

30-
So far, we have been writing code in `.R` scripts. This is excellent for data analysis, but what happens when you need to share your findings with a colleague or a library director? You might copy a plot into a Word document or an email, then type out your interpretation.
26+
So far, we have been writing code in `.R` scripts. This is excellent for data analysis, but what happens when you need to share your findings with a colleague or a library director? You might copy a plot into a Word document or an email, then type out your interpretation.
3127

3228
But what if the data changes next month? You would have to re-run your script, re-save the plot, copy it back into Word, and update your text. This manual process is prone to errors and tedious.
3329

@@ -37,21 +33,19 @@ But what if the data changes next month? You would have to re-run your script, r
3733

3834
To create a new Quarto document in RStudio:
3935

40-
1. Click the **File** menu.
41-
2. Select **New File** > **Quarto Document...**
42-
3. In the dialog box, give your document a **Title** (e.g., "Library Usage Report") and enter your name as **Author**.
43-
4. Ensure **HTML** is selected as the output format.
44-
5. Click **Create**.
36+
1. Click the **File** menu.
37+
2. Select **New File** \> **Quarto Document...**
38+
3. In the dialog box, give your document a **Title** (e.g., "Library Usage Report") and enter your name as **Author**.
39+
4. Ensure **HTML** is selected as the output format.
40+
5. Click **Create**.
4541

4642
RStudio will open a new file with some example content. Notice the file extension is `.qmd`.
4743

48-
::::::::::::::::::::::::::::::::::::::::: callout
49-
44+
::: callout
5045
## Quarto vs. RMarkdown
5146

5247
If you have used R before, you might be familiar with RMarkdown (`.Rmd`). Quarto (`.qmd`) is the next-generation version of RMarkdown. It works very similarly but supports more languages (like Python and Julia) and has better features for scientific publishing.
53-
54-
:::::::::::::::::::::::::::::::::::::::::
48+
:::
5549

5650
## Anatomy of a Quarto Document
5751

@@ -61,7 +55,7 @@ A Quarto document has three main parts:
6155

6256
At the very top, enclosed between two lines of `---`, is the **YAML Header**. This contains metadata about the document.
6357

64-
```yaml
58+
``` yaml
6559
---
6660
title: "Library Usage Report"
6761
author: "Your Name"
@@ -71,19 +65,18 @@ format: html
7165

7266
### 2. Markdown Text
7367

74-
The white space is where you write your narrative. You use **Markdown** syntax to format text.
68+
The white space is where you write your narrative. You use **Markdown** syntax to format text.
7569

76-
- `**Bold**` for **bold text**
77-
- `*Italics*` for *italics*
78-
- `# Heading 1` for a main title
79-
- `## Heading 2` for a section title
80-
- `- List item` for bullet points
70+
- `**Bold**` for **bold text**
71+
- `*Italics*` for *italics*
72+
- `# Heading 1` for a main title
73+
- `## Heading 2` for a section title
74+
- `- List item` for bullet points
8175

8276
### 3. Code Chunks
8377

84-
Code chunks are where your R code lives. They start with ` ```{r} ` and end with ` ``` `.
78+
Code chunks are where your R code lives. They start with ```` ```{r} ```` and end with ```` ``` ````.
8579

86-
````
8780

8881
``` r
8982
# This is a code chunk
@@ -99,7 +92,6 @@ summary(cars)
9992
3rd Qu.:19.0 3rd Qu.: 56.00
10093
Max. :25.0 Max. :120.00
10194
```
102-
````
10395

10496
You can insert a new chunk by clicking the **+C** button in the editor toolbar, or by pressing <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>I</kbd> (Windows/Linux) or <kbd>Cmd</kbd>+<kbd>Option</kbd>+<kbd>I</kbd> (Mac).
10597

@@ -110,53 +102,27 @@ Let's clean up the example file and create a report using our `books` data.
110102
1. Delete everything in the file *below* the YAML header.
111103
2. Add a new **setup** code chunk to load our libraries and prepare the data.
112104

113-
```{{r}}
114-
#| label: setup
115-
#| include: false
116-
117-
library(tidyverse)
118-
119-
# Load data and rename columns for clarity
120-
books2 <- read_csv("data/books.csv") %>%
121-
rename(
122-
subCollection = BCODE1,
123-
tot_chkout = TOT.CHKOUT,
124-
format = BCODE2
125-
) %>%
126-
mutate(
127-
subCollection = recode(subCollection,
128-
"-" = "general collection",
129-
j = "juvenile",
130-
b = "k-12 materials"
131-
)
132-
)
133-
```
134105

135-
::::::::::::::::::::::::::::::::::::::::: callout
136106

107+
::: callout
137108
## Chunk Options
138109

139-
Notice the lines starting with `#|`. These are **chunk options**.
140-
- `#| label: setup` gives the chunk a name.
141-
- `#| include: false` runs the code but hides the code and output from the final report. This is great for loading data silently.
142-
143-
:::::::::::::::::::::::::::::::::::::::::
110+
Notice the lines starting with `#|`. These are **chunk options**. - `#| label: setup` gives the chunk a name. - `#| include: false` runs the code but hides the code and output from the final report. This is great for loading data silently.
111+
:::
144112

145113
### Adding Analysis
146114

147115
Now, let's add a section header and some text.
148116

149-
```markdown
117+
``` markdown
150118
## High Usage Items
151119

152120
We are analyzing items with more than 10 checkouts to understand circulation patterns across sub-collections.
153121
```
154122

155123
Next, insert a new code chunk and paste the plotting code we developed in the previous episode (ggplot2).
156124

157-
````
158125
<img src="fig/05-reproducible-reports-rendered-plot-high-usage-1.png" alt="" style="display: block; margin: auto;" />
159-
````
160126

161127
Setting `#| echo: false` will display the *plot* in the report, but hide the R *code* that generated it. This is often preferred for reports intended for non-coders.
162128

@@ -165,82 +131,61 @@ Setting `#| echo: false` will display the *plot* in the report, but hide the R *
165131
Now comes the magic. Click the **Render** button (blue arrow icon) at the top of the editor pane.
166132

167133
RStudio will:
134+
168135
1. Run all your code chunks from scratch.
169136
2. Generate the plots and results.
170137
3. Combine them with your text.
171138
4. Create a new file named `library_usage_report.html` in your project folder.
172139
5. Open a preview of the report.
173140

174-
::::::::::::::::::::::::::::::::::::::: challenge
175-
141+
:::: challenge
176142
## Challenge: Add a Summary Table
177143

178144
1. Add a new header `## Summary Statistics` to your Quarto document.
179145
2. Insert a new code chunk.
180146
3. Write code to calculate the mean checkouts per format (Hint: use `group_by(format)` and `summarize()`).
181147
4. Render the document again to see your new table included in the report.
182148

183-
::::::::::::::: solution
184-
149+
::: solution
185150
## Solution
186151

187152
Add this to your document:
188153

189-
```markdown
154+
``` markdown
190155
## Summary Statistics
191156

192157
The table below shows the average checkouts for each item format.
193158
```
194159

195-
````
160+
```{{r}}
161+
#| label: summary-table
196162
197-
``` r
198163
books2 %>%
199164
group_by(format) %>%
200165
summarize(mean_checkouts = mean(tot_chkout, na.rm = TRUE)) %>%
201166
arrange(desc(mean_checkouts))
202167
```
203168

204-
``` output
205-
# A tibble: 10 × 2
206-
format mean_checkouts
207-
<chr> <dbl>
208-
1 map 10.6
209-
2 book 3.23
210-
3 kit/object 1.33
211-
4 cd-rom 0.333
212-
5 e-gov doc 0.0402
213-
6 image 0.0275
214-
7 microform 0.00122
215-
8 database 0
216-
9 online video 0
217-
10 serial 0
218-
```
219-
````
220-
221169
Render the document to see the updated report.
222-
223-
:::::::::::::::::::::::::
224-
225-
::::::::::::::::::::::::::::::::::::::::::::::::::
170+
:::
171+
::::
226172

227173
## Why This Matters
228174

229-
By using Quarto, your report is now **reproducible**.
175+
By using Quarto, your report is now **reproducible**.
230176

231177
If you download a new version of `books.csv` next month:
178+
232179
1. Save it to your `data/` folder.
233180
2. Open your Quarto document.
234181
3. Click **Render**.
235182

236183
Your report will automatically update with the new data, creating a fresh plot and table without you having to copy-paste a single thing.
237184

238-
:::::::::::::::::::::::::::::::::::::::: keypoints
239-
240-
- **Quarto** allows you to mix code and text to create reproducible reports.
241-
- Use the **YAML header** to configure document metadata like title and output format.
242-
- **Code chunks** run R code and can display or hide input/output using options like `#| echo: false`.
243-
- **Rendering** the document executes the code and produces the final output (HTML, PDF, etc.).
244-
- This workflow saves time and reduces errors when reporting on data that changes over time.
245-
246-
::::::::::::::::::::::::::::::::::::::::::::::::::
185+
::: keypoints
186+
- **Quarto** allows you to mix code and text to create reproducible reports.
187+
- Use the **YAML header** to configure document metadata like title and output format.
188+
- **Code chunks** run R code and can display or hide input/output using options like `#| echo: false`.
189+
- **Rendering** the document executes the code and produces the final output (HTML, PDF, etc.).
190+
- This workflow saves time and reduces errors when reporting on data that changes over time.
191+
:::
-2.21 KB
Loading

md5sum.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"episodes/02-starting-with-data.Rmd" "4c16ab36f73079f60a08ab78681e67af" "site/built/02-starting-with-data.md" "2026-02-03"
99
"episodes/03-data-cleaning-and-transformation.Rmd" "a35ff21cbaa4066b038e0db9d25e8ea2" "site/built/03-data-cleaning-and-transformation.md" "2026-02-03"
1010
"episodes/04-data-viz-ggplot.Rmd" "38677fdaedc3e86f26d4168831da3daa" "site/built/04-data-viz-ggplot.md" "2026-02-19"
11-
"episodes/05-reproducible-reports.Rmd" "65c2ee2cc0bba7f9fbbeac55e5d2aa51" "site/built/05-reproducible-reports.md" "2026-02-19"
11+
"episodes/05-reproducible-reports.Rmd" "9ab3b684bc0968b584273721dff186ea" "site/built/05-reproducible-reports.md" "2026-02-20"
1212
"instructors/instructor-notes.md" "a59fd3b94c07c3fe3218c054a0f03277" "site/built/instructor-notes.md" "2026-02-03"
1313
"learners/discuss.md" "2758e2e5abd231d82d25c6453d8abbc6" "site/built/discuss.md" "2026-02-03"
1414
"learners/reference.md" "dda49515f46cca6a1a8e7e195e66e73c" "site/built/reference.md" "2026-02-03"

0 commit comments

Comments
 (0)