You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
72
+
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.
77
73
78
74
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.
79
75
@@ -83,21 +79,19 @@ But what if the data changes next month? You would have to re-run your script, r
83
79
84
80
To create a new Quarto document in RStudio:
85
81
86
-
1. Click the **File** menu.
87
-
2. Select **New File** > **Quarto Document...**
88
-
3. In the dialog box, give your document a **Title** (e.g., "Library Usage Report") and enter your name as **Author**.
89
-
4. Ensure **HTML** is selected as the output format.
90
-
5. Click **Create**.
82
+
1.Click the **File** menu.
83
+
2.Select **New File**\>**Quarto Document...**
84
+
3.In the dialog box, give your document a **Title** (e.g., "Library Usage Report") and enter your name as **Author**.
85
+
4.Ensure **HTML** is selected as the output format.
86
+
5.Click **Create**.
91
87
92
88
RStudio will open a new file with some example content. Notice the file extension is `.qmd`.
93
89
94
-
::::::::::::::::::::::::::::::::::::::::: callout
95
-
90
+
::: callout
96
91
## Quarto vs. RMarkdown
97
92
98
93
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.
99
-
100
-
:::::::::::::::::::::::::::::::::::::::::
94
+
:::
101
95
102
96
## Anatomy of a Quarto Document
103
97
@@ -107,7 +101,7 @@ A Quarto document has three main parts:
107
101
108
102
At the very top, enclosed between two lines of `---`, is the **YAML Header**. This contains metadata about the document.
109
103
110
-
```yaml
104
+
```yaml
111
105
---
112
106
title: "Library Usage Report"
113
107
author: "Your Name"
@@ -117,24 +111,22 @@ format: html
117
111
118
112
### 2. Markdown Text
119
113
120
-
The white space is where you write your narrative. You use **Markdown** syntax to format text.
114
+
The white space is where you write your narrative. You use **Markdown** syntax to format text.
121
115
122
-
-`**Bold**` for **bold text**
123
-
-`*Italics*` for *italics*
124
-
-`# Heading 1` for a main title
125
-
-`## Heading 2` for a section title
126
-
-`- List item` for bullet points
116
+
-`**Bold**` for **bold text**
117
+
-`*Italics*` for *italics*
118
+
-`# Heading 1` for a main title
119
+
-`## Heading 2` for a section title
120
+
-`- List item` for bullet points
127
121
128
122
### 3. Code Chunks
129
123
130
-
Code chunks are where your R code lives. They start with ` ```{r} ` and end with ` ``` `.
124
+
Code chunks are where your R code lives. They start with ```` ```{r} ```` and end with ```` ``` ````.
131
125
132
-
````
133
126
```{r}
134
127
# This is a code chunk
135
128
summary(cars)
136
129
```
137
-
````
138
130
139
131
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).
140
132
@@ -145,7 +137,7 @@ Let's clean up the example file and create a report using our `books` data.
145
137
1. Delete everything in the file *below* the YAML header.
146
138
2. Add a new **setup** code chunk to load our libraries and prepare the data.
Notice the lines starting with `#|`. These are **chunk options**.
175
-
-`#| label: setup` gives the chunk a name.
176
-
-`#| include: false` runs the code but hides the code and output from the final report. This is great for loading data silently.
177
-
178
-
:::::::::::::::::::::::::::::::::::::::::
165
+
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.
166
+
:::
179
167
180
168
### Adding Analysis
181
169
182
170
Now, let's add a section header and some text.
183
171
184
-
```markdown
172
+
```markdown
185
173
## High Usage Items
186
174
187
175
We are analyzing items with more than 10 checkouts to understand circulation patterns across sub-collections.
188
176
```
189
177
190
178
Next, insert a new code chunk and paste the plotting code we developed in the previous episode (ggplot2).
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.
217
203
@@ -220,67 +206,61 @@ Setting `#| echo: false` will display the *plot* in the report, but hide the R *
220
206
Now comes the magic. Click the **Render** button (blue arrow icon) at the top of the editor pane.
221
207
222
208
RStudio will:
209
+
223
210
1. Run all your code chunks from scratch.
224
211
2. Generate the plots and results.
225
212
3. Combine them with your text.
226
213
4. Create a new file named `library_usage_report.html` in your project folder.
227
214
5. Open a preview of the report.
228
215
229
-
::::::::::::::::::::::::::::::::::::::: challenge
230
-
216
+
:::: challenge
231
217
## Challenge: Add a Summary Table
232
218
233
219
1. Add a new header `## Summary Statistics` to your Quarto document.
234
220
2. Insert a new code chunk.
235
221
3. Write code to calculate the mean checkouts per format (Hint: use `group_by(format)` and `summarize()`).
236
222
4. Render the document again to see your new table included in the report.
237
223
238
-
::::::::::::::: solution
239
-
224
+
::: solution
240
225
## Solution
241
226
242
227
Add this to your document:
243
228
244
-
```markdown
229
+
```markdown
245
230
## Summary Statistics
246
231
247
232
The table below shows the average checkouts for each item format.
0 commit comments