Skip to content

Commit 28a208d

Browse files
committed
format R cell in .qmd too
1 parent b23859a commit 28a208d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+516
-394
lines changed

.vscode/settings.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"editor.defaultFormatter": "Posit.air-vscode"
88
},
99
"[quarto]": {
10-
"editor.formatOnSave": true
10+
"editor.formatOnSave": true,
11+
"editor.defaultFormatter": "quarto.quarto"
1112
},
1213
"[html]": {
1314
"editor.formatOnSave": false
@@ -19,5 +20,7 @@
1920
"deno.lint": true,
2021
"deno.unstable": true,
2122
"deno.importMap": "./src/import_map.json",
22-
"deno.disablePaths": ["tests/integration/playwright/"]
23+
"deno.disablePaths": ["tests/integration/playwright/"],
24+
// opt-out lintr as we use air formatter
25+
"r.lsp.diagnostics": false
2326
}

tests/docs/manuscript/qmd-full/notebook.qmd

Lines changed: 63 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ df_ign <- df_ign |>
1818
`Depth(km)` >= 28 ~ "Deep (>28km)",
1919
`Depth(km)` >= 18 ~ "Interchange (18km>x>28km)",
2020
TRUE ~ "Shallow (< 18km)"
21-
))
21+
)
22+
)
2223
df_ign
2324
```
2425

@@ -27,14 +28,15 @@ df_ign
2728
#| label: epochs
2829
cut_times <- ymd_hms(c("2021-09-11", "2021-09-19 14:13:00", "2021-10-01", "2021-12-01", "2021-12-31", "2022-01-01"), truncated = 3)
2930
epochs <- tibble(
30-
start = cut_times[-length(cut_times)],
31-
end = cut_times[-1],
31+
start = cut_times[-length(cut_times)],
32+
end = cut_times[-1],
3233
label = c("pre", "early", "phase1", "phase2", "phase3"),
33-
text = c('Pre\nEruptive\nSwarm',
34-
'Early Eruptive\nPhase',
35-
'Main Eruptive Phase\n(sustained gas and lava ejection)',
36-
'Final Eruptive Phase\n(reducing gas and lava ejection)',
37-
NA
34+
text = c(
35+
"Pre\nEruptive\nSwarm",
36+
"Early Eruptive\nPhase",
37+
"Main Eruptive Phase\n(sustained gas and lava ejection)",
38+
"Final Eruptive Phase\n(reducing gas and lava ejection)",
39+
NA
3840
)
3941
)
4042
```
@@ -43,19 +45,22 @@ epochs <- tibble(
4345
```{r}
4446
#| label: "erupt-data"
4547
mag_breaks <- c(0, 1, 2, 3, 4, 6)
46-
mag_labels <- c("0 < M <= 1","1 < M <= 2","2 < M <= 3","3 < M <= 4","M > 4")
48+
mag_labels <- c("0 < M <= 1", "1 < M <= 2", "2 < M <= 3", "3 < M <= 4", "M > 4")
4749
df_erupt <- df_ign |>
4850
filter(Date < as.Date("2022-01-01") & Date > as.Date("2021-09-11")) |>
49-
mutate(Magnitude_categories = cut(Magnitude,
50-
breaks = mag_breaks, labels = mag_labels, right = FALSE))
51+
mutate(Magnitude_categories = cut(Magnitude,
52+
breaks = mag_breaks, labels = mag_labels, right = FALSE
53+
))
5154
```
5255

5356

5457
```{r}
5558
#| label: colors
56-
colors <- c("#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a",
57-
"#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2",
58-
"#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5")
59+
colors <- c(
60+
"#1f77b4", "#aec7e8", "#ff7f0e", "#ffbb78", "#2ca02c", "#98df8a",
61+
"#d62728", "#ff9896", "#9467bd", "#c5b0d5", "#8c564b", "#c49c94", "#e377c2",
62+
"#f7b6d2", "#7f7f7f", "#c7c7c7", "#bcbd22", "#dbdb8d", "#17becf", "#9edae5"
63+
)
5964
```
6065

6166
```{r}
@@ -64,41 +69,55 @@ colors <- c("#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a",
6469
#| fig-width: 24
6570
#| fig-height: 12
6671
eruption <- ymd_hms("2021-09-19 14:13:00")
67-
date_axis_breaks <- as.Date("2021-10-15") + months(rep(0:2, each = 2)) -
68-
days(rep(c(14, 0), times = 3))
72+
date_axis_breaks <- as.Date("2021-10-15") + months(rep(0:2, each = 2)) -
73+
days(rep(c(14, 0), times = 3))
6974
date_axis_breaks <- c(eruption, date_axis_breaks[-1])
7075
7176
# Custom Magnitude Scale transform
7277
trans_mag <- scales::trans_new(
7378
name = "Magnitude transformation",
74-
transform = \(x) 3*2^(1.3*x),
75-
inverse = \(x) (1/1.3) * log2(x/3)
79+
transform = \(x) 3 * 2^(1.3 * x),
80+
inverse = \(x) (1 / 1.3) * log2(x / 3)
7681
)
7782
78-
83+
7984
df_erupt |>
80-
arrange(Magnitude) |>
81-
ggplot(aes(DateTime, `Depth(km)`)) +
82-
geom_point(aes(fill = Magnitude_categories, size = Magnitude,
83-
alpha = Magnitude_categories), shape = 21, color = "black") +
85+
arrange(Magnitude) |>
86+
ggplot(aes(DateTime, `Depth(km)`)) +
87+
geom_point(aes(
88+
fill = Magnitude_categories, size = Magnitude,
89+
alpha = Magnitude_categories
90+
), shape = 21, color = "black") +
8491
geom_vline(xintercept = eruption, color = colors[7]) +
85-
annotate("text", x = eruption, y = 20, label = "ERUPTION",
86-
color = colors[7], angle = 90, hjust = 1, vjust = -0.2, size = 6) +
87-
annotate("rect", xmin = epochs$start, xmax = epochs$end,
88-
ymin = -Inf, ymax = Inf, fill = colors[c(1, 3, 5, 7, 7)], alpha = 0.1) +
89-
annotate("text", x = epochs$start + 0.5*(epochs$end - epochs$start), y = -4,
90-
label = epochs$text, color = colors[c(1, 3, 5, 7, NA)], size = 7) +
91-
scale_y_continuous("Depth (km)", trans = scales::reverse_trans(),
92-
breaks = seq(0, 40, 10), limits = c( 45, -5), sec.axis = dup_axis()) +
93-
scale_x_datetime("Eruption Timeline", expand = c(0, 0),
94-
date_labels = "%Y-%m-%d", breaks = date_axis_breaks) +
92+
annotate("text",
93+
x = eruption, y = 20, label = "ERUPTION",
94+
color = colors[7], angle = 90, hjust = 1, vjust = -0.2, size = 6
95+
) +
96+
annotate("rect",
97+
xmin = epochs$start, xmax = epochs$end,
98+
ymin = -Inf, ymax = Inf, fill = colors[c(1, 3, 5, 7, 7)], alpha = 0.1
99+
) +
100+
annotate("text",
101+
x = epochs$start + 0.5 * (epochs$end - epochs$start), y = -4,
102+
label = epochs$text, color = colors[c(1, 3, 5, 7, NA)], size = 7
103+
) +
104+
scale_y_continuous("Depth (km)",
105+
trans = scales::reverse_trans(),
106+
breaks = seq(0, 40, 10), limits = c(45, -5), sec.axis = dup_axis()
107+
) +
108+
scale_x_datetime("Eruption Timeline",
109+
expand = c(0, 0),
110+
date_labels = "%Y-%m-%d", breaks = date_axis_breaks
111+
) +
95112
scale_fill_manual("Event Magnitude (M)", values = colors[c(13, 17, 5, 3, 7)]) +
96113
scale_alpha_manual("Event Magnitude (M)", values = c(0.3, 0.4, 0.5, 0.6, 0.8)) +
97-
scale_size("Event Magnitude (M)", breaks = 1:5, labels = mag_labels,
98-
trans = trans_mag) +
99-
theme_bw(base_size = 20, base_family = "Helvetica") +
114+
scale_size("Event Magnitude (M)",
115+
breaks = 1:5, labels = mag_labels,
116+
trans = trans_mag
117+
) +
118+
theme_bw(base_size = 20, base_family = "Helvetica") +
100119
theme(
101-
legend.position = c(0.01, 0.01),
120+
legend.position = c(0.01, 0.01),
102121
legend.justification = c("left", "bottom"),
103122
panel.grid.major.x = element_blank(),
104123
panel.grid.minor.x = element_blank(),
@@ -117,17 +136,18 @@ df_erupt |>
117136
#| fig-width: 8
118137
blue <- "#336699"
119138
120-
p <- df_ign |>
139+
p <- df_ign |>
121140
ggplot(aes(Magnitude, `Depth(km)`)) +
122141
geom_point(alpha = 0.6, color = blue) +
123-
geom_density2d(color = blue, n = 100, h = c(1, 8), bins = 20) +
142+
geom_density2d(color = blue, n = 100, h = c(1, 8), bins = 20) +
124143
scale_y_continuous(trans = "reverse") +
125-
coord_fixed(ratio = 1/8) +
126-
labs(title = "Cumulative Events 01-01-2017 to 01-01-2022") +
144+
coord_fixed(ratio = 1 / 8) +
145+
labs(title = "Cumulative Events 01-01-2017 to 01-01-2022") +
127146
theme_bw() +
128147
theme(
129-
plot.title = element_text(hjust = 0.5, margin = margin(t = 20, b = 20)))
130-
148+
plot.title = element_text(hjust = 0.5, margin = margin(t = 20, b = 20))
149+
)
150+
131151
132152
ggMarginal(p, type = "histogram", bins = 20, fill = blue, color = "white")
133153
```

tests/docs/manuscript/qmd-single/index.qmd

Lines changed: 64 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ df_ign <- df_ign |>
131131
`Depth(km)` >= 28 ~ "Deep (>28km)",
132132
`Depth(km)` >= 18 ~ "Interchange (18km>x>28km)",
133133
TRUE ~ "Shallow (< 18km)"
134-
))
134+
)
135+
)
135136
df_ign
136137
```
137138
@@ -140,14 +141,15 @@ df_ign
140141
#| label: epochs
141142
cut_times <- ymd_hms(c("2021-09-11", "2021-09-19 14:13:00", "2021-10-01", "2021-12-01", "2021-12-31", "2022-01-01"), truncated = 3)
142143
epochs <- tibble(
143-
start = cut_times[-length(cut_times)],
144-
end = cut_times[-1],
144+
start = cut_times[-length(cut_times)],
145+
end = cut_times[-1],
145146
label = c("pre", "early", "phase1", "phase2", "phase3"),
146-
text = c('Pre\nEruptive\nSwarm',
147-
'Early Eruptive\nPhase',
148-
'Main Eruptive Phase\n(sustained gas and lava ejection)',
149-
'Final Eruptive Phase\n(reducing gas and lava ejection)',
150-
NA
147+
text = c(
148+
"Pre\nEruptive\nSwarm",
149+
"Early Eruptive\nPhase",
150+
"Main Eruptive Phase\n(sustained gas and lava ejection)",
151+
"Final Eruptive Phase\n(reducing gas and lava ejection)",
152+
NA
151153
)
152154
)
153155
```
@@ -156,19 +158,22 @@ epochs <- tibble(
156158
```{r}
157159
#| label: "erupt-data"
158160
mag_breaks <- c(0, 1, 2, 3, 4, 6)
159-
mag_labels <- c("0 < M <= 1","1 < M <= 2","2 < M <= 3","3 < M <= 4","M > 4")
161+
mag_labels <- c("0 < M <= 1", "1 < M <= 2", "2 < M <= 3", "3 < M <= 4", "M > 4")
160162
df_erupt <- df_ign |>
161163
filter(Date < as.Date("2022-01-01") & Date > as.Date("2021-09-11")) |>
162-
mutate(Magnitude_categories = cut(Magnitude,
163-
breaks = mag_breaks, labels = mag_labels, right = FALSE))
164+
mutate(Magnitude_categories = cut(Magnitude,
165+
breaks = mag_breaks, labels = mag_labels, right = FALSE
166+
))
164167
```
165168
166169
167170
```{r}
168171
#| label: colors
169-
colors <- c("#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a",
170-
"#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2",
171-
"#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5")
172+
colors <- c(
173+
"#1f77b4", "#aec7e8", "#ff7f0e", "#ffbb78", "#2ca02c", "#98df8a",
174+
"#d62728", "#ff9896", "#9467bd", "#c5b0d5", "#8c564b", "#c49c94", "#e377c2",
175+
"#f7b6d2", "#7f7f7f", "#c7c7c7", "#bcbd22", "#dbdb8d", "#17becf", "#9edae5"
176+
)
172177
```
173178
174179
@@ -178,41 +183,55 @@ colors <- c("#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a",
178183
#| fig-width: 24
179184
#| fig-height: 12
180185
eruption <- ymd_hms("2021-09-19 14:13:00")
181-
date_axis_breaks <- as.Date("2021-10-15") + months(rep(0:2, each = 2)) -
182-
days(rep(c(14, 0), times = 3))
186+
date_axis_breaks <- as.Date("2021-10-15") + months(rep(0:2, each = 2)) -
187+
days(rep(c(14, 0), times = 3))
183188
date_axis_breaks <- c(eruption, date_axis_breaks[-1])
184189
185190
# Custom Magnitude Scale transform
186191
trans_mag <- scales::trans_new(
187192
name = "Magnitude transformation",
188-
transform = \(x) 3*2^(1.3*x),
189-
inverse = \(x) (1/1.3) * log2(x/3)
193+
transform = \(x) 3 * 2^(1.3 * x),
194+
inverse = \(x) (1 / 1.3) * log2(x / 3)
190195
)
191196
192-
197+
193198
df_erupt |>
194-
arrange(Magnitude) |>
195-
ggplot(aes(DateTime, `Depth(km)`)) +
196-
geom_point(aes(fill = Magnitude_categories, size = Magnitude,
197-
alpha = Magnitude_categories), shape = 21, color = "black") +
199+
arrange(Magnitude) |>
200+
ggplot(aes(DateTime, `Depth(km)`)) +
201+
geom_point(aes(
202+
fill = Magnitude_categories, size = Magnitude,
203+
alpha = Magnitude_categories
204+
), shape = 21, color = "black") +
198205
geom_vline(xintercept = eruption, color = colors[7]) +
199-
annotate("text", x = eruption, y = 20, label = "ERUPTION",
200-
color = colors[7], angle = 90, hjust = 1, vjust = -0.2, size = 6) +
201-
annotate("rect", xmin = epochs$start, xmax = epochs$end,
202-
ymin = -Inf, ymax = Inf, fill = colors[c(1, 3, 5, 7, 7)], alpha = 0.1) +
203-
annotate("text", x = epochs$start + 0.5*(epochs$end - epochs$start), y = -4,
204-
label = epochs$text, color = colors[c(1, 3, 5, 7, NA)], size = 7) +
205-
scale_y_continuous("Depth (km)", trans = scales::reverse_trans(),
206-
breaks = seq(0, 40, 10), limits = c( 45, -5), sec.axis = dup_axis()) +
207-
scale_x_datetime("Eruption Timeline", expand = c(0, 0),
208-
date_labels = "%Y-%m-%d", breaks = date_axis_breaks) +
206+
annotate("text",
207+
x = eruption, y = 20, label = "ERUPTION",
208+
color = colors[7], angle = 90, hjust = 1, vjust = -0.2, size = 6
209+
) +
210+
annotate("rect",
211+
xmin = epochs$start, xmax = epochs$end,
212+
ymin = -Inf, ymax = Inf, fill = colors[c(1, 3, 5, 7, 7)], alpha = 0.1
213+
) +
214+
annotate("text",
215+
x = epochs$start + 0.5 * (epochs$end - epochs$start), y = -4,
216+
label = epochs$text, color = colors[c(1, 3, 5, 7, NA)], size = 7
217+
) +
218+
scale_y_continuous("Depth (km)",
219+
trans = scales::reverse_trans(),
220+
breaks = seq(0, 40, 10), limits = c(45, -5), sec.axis = dup_axis()
221+
) +
222+
scale_x_datetime("Eruption Timeline",
223+
expand = c(0, 0),
224+
date_labels = "%Y-%m-%d", breaks = date_axis_breaks
225+
) +
209226
scale_fill_manual("Event Magnitude (M)", values = colors[c(13, 17, 5, 3, 7)]) +
210227
scale_alpha_manual("Event Magnitude (M)", values = c(0.3, 0.4, 0.5, 0.6, 0.8)) +
211-
scale_size("Event Magnitude (M)", breaks = 1:5, labels = mag_labels,
212-
trans = trans_mag) +
213-
theme_bw(base_size = 20, base_family = "Helvetica") +
228+
scale_size("Event Magnitude (M)",
229+
breaks = 1:5, labels = mag_labels,
230+
trans = trans_mag
231+
) +
232+
theme_bw(base_size = 20, base_family = "Helvetica") +
214233
theme(
215-
legend.position = c(0.01, 0.01),
234+
legend.position = c(0.01, 0.01),
216235
legend.justification = c("left", "bottom"),
217236
panel.grid.major.x = element_blank(),
218237
panel.grid.minor.x = element_blank(),
@@ -233,19 +252,20 @@ df_erupt |>
233252
#| fig-width: 8
234253
blue <- "#336699"
235254
236-
p <- df_ign |>
255+
p <- df_ign |>
237256
ggplot(aes(Magnitude, `Depth(km)`)) +
238257
geom_point(alpha = 0.6, color = blue) +
239-
geom_density2d(color = blue, n = 100, h = c(1, 8), bins = 20) +
258+
geom_density2d(color = blue, n = 100, h = c(1, 8), bins = 20) +
240259
scale_y_continuous(trans = "reverse") +
241-
coord_fixed(ratio = 1/8) +
242-
labs(title = "Cumulative Events 01-01-2017 to 01-01-2022") +
260+
coord_fixed(ratio = 1 / 8) +
261+
labs(title = "Cumulative Events 01-01-2017 to 01-01-2022") +
243262
theme_bw() +
244263
theme(
245-
plot.title = element_text(hjust = 0.5, margin = margin(t = 20, b = 20)))
246-
264+
plot.title = element_text(hjust = 0.5, margin = margin(t = 20, b = 20))
265+
)
266+
247267
248-
ggMarginal(p, type = "histogram", bins = 20, fill = blue, color = "white")
268+
ggMarginal(p, type = "histogram", bins = 20, fill = blue, color = "white")
249269
```
250270
251271
# Results

tests/docs/ojs/test-dependency-traversal-2.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ format: html
44
---
55

66
```{r}
7-
print(c(1,2,3))
7+
print(c(1, 2, 3))
88
```
99

1010
```{ojs}

tests/docs/page-layout/tufte-html.qmd

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ You can use the `kable()` function from the **knitr** package to format tables t
140140
```{r}
141141
#| tbl-cap-location: margin
142142
knitr::kable(
143-
mtcars[1:6, 1:6], caption = 'A subset of mtcars.'
143+
mtcars[1:6, 1:6],
144+
caption = "A subset of mtcars."
144145
)
145146
```
146147

@@ -188,7 +189,7 @@ Then two plots from the same code chunk placed in different figure environments:
188189

189190
```{r}
190191
#| echo: false
191-
knitr::kable(head(iris[,c(1,2,3,4)], 15))
192+
knitr::kable(head(iris[, c(1, 2, 3, 4)], 15))
192193
```
193194

194195
```{r}
@@ -205,7 +206,7 @@ plot(iris)
205206

206207
```{r}
207208
#| echo: false
208-
knitr::kable(head(iris[,c(1,2,3,4)], 12))
209+
knitr::kable(head(iris[, c(1, 2, 3, 4)], 12))
209210
```
210211

211212
We blended some tables in the above code chunk only as _placeholders_ to make sure there is enough vertical space among the margin figures, otherwise they will be stacked tightly together. For a practical document, you should not insert too many margin figures consecutively and make the margin crowded.

0 commit comments

Comments
 (0)