-
Notifications
You must be signed in to change notification settings - Fork 1
/
tudelft_20nov2024.qmd
374 lines (219 loc) · 6.41 KB
/
tudelft_20nov2024.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
---
title: "Tips for reproducibility in R"
author: "Sam Langton -- Amsterdam UMC"
subtitle: "<br> <br> <br> TU Delft, 20 November 2024"
format:
revealjs:
auto-stretch: false
editor: visual
editor_options:
chunk_output_type: console
date-format: long
---
## Who am I?
::: columns
::: {.column width="60%"}
- Research software consultant at AUMC
- Research background: spatial patterning of crime
- R enthusiast
- Promoting & training open software
:::
::: {.column width="40%"}
<center>
![](https://github.com/langtonhugh/website_academic/blob/master/content/authors/admin/avatar.jpg?raw=true){width="200"}
![](img/crime_map.png){width="300"}
</center>
:::
:::
## What is reproducibility?
> "We define reproducible research as work that can be independently recreated from the same data and the same code that the original team used."
<center>
![Source: [The Turing Way](https://book.the-turing-way.org/reproducible-research/overview/overview-definitions)](https://book.the-turing-way.org/_images/reproducible-matrix.jpg){width="500"}
</center>
## A personal tale
<br>
Publishing an [open science replication paper](https://www.tandfonline.com/doi/full/10.1080/15614263.2022.2102494).
<br>
<center>![](img/paper_header.png){width="900"}</center>
##
<center>![](img/spongebob.png){width="450"}</center>
## A personal tale
<br>
...and I could not reproduce the findings.
<br>
<br>
<br>
(It was fixed, but with [some effort](https://github.com/langtonhugh/demand_detroit) and a bit of luck).
##
<center>![](img/drake.png){width="800"}</center>
## Focus your energy
1. Script *everything* ([De Graaff., 2021](https://www.dropbox.com/s/vn7rn9m5ht2miol/reproducibility.pdf?e=1&dl=0))
2. Project folders
3. Options in RStudio
4. `renv`
5. Quarto
## Script *everything*
<br>
"R is a statistics software" `r emo::ji("angry")` Well, partly... but it can (probably) be used for your [entire computational workflow](https://wec.wur.nl/dse/images/11/tidyverse%20workflow.png).
<br>
If you **can** script it, then **script it**.
<br>
RStudio can also support other languages (e.g., [Python](https://posit.co/blog/three-ways-to-program-in-python-with-rstudio/))
## Project folders
<br> <br>
<center>
![Source: [Jenny Bryan](https://www.tidyverse.org/blog/2017/12/workflow-vs-script/)](img/setwd.png){width="700"}
</center>
## Project folders
<br>
<center>
![](img/project_screenshot.png){width="700"}
<br>
![](img/folder_screenshot.png){width="800"}
</center>
## Project folders
Avoids this:
```{r, eval = FALSE, echo = TRUE}
setwd("C:/SamL/my_projects/ridiculous_folder_name/data")
raw_data_df <- read_csv("raw_records.csv")
```
<br> And this:
```{r, eval = FALSE, echo = TRUE}
raw_data_df <- read_csv("C:/SamL/my_projects/ridiculous_folder_name/data/raw_records.csv")
```
<br>
But instead:
```{r, eval = FALSE, echo = TRUE}
raw_data_df <- read_csv("data/raw_records.csv")
```
</center>
<!-- ## Options in RStudio -->
<!-- <br> -->
<!-- <br> -->
<!-- <center> -->
<!-- `Ctrl + shift + F10` -->
<!-- <br> -->
<!-- `Ctrl + A` -->
<!-- <br> -->
<!-- `Ctrl + Enter` -->
<!-- </center> -->
## Options in RStudio
<br>
<center>
![](img/global_options.png){width="700"}
*Workspaces are pure evil. Turn them off.*
<!-- ## `here` package -->
<!-- Bad: -->
<!-- ```{r, eval = FALSE, echo = TRUE} -->
<!-- raw_data_df <- read_csv("C:/SamL/my_projects/ridiculous_folder_name/data/raw_records.csv") -->
<!-- ``` -->
<!-- <br> -->
<!-- Good: -->
<!-- ```{r, eval = FALSE, echo = TRUE} -->
<!-- raw_data_df <- read_csv("data/raw_records.csv") -->
<!-- ``` -->
<!-- <br> -->
<!-- Even better: -->
<!-- ```{r, eval = FALSE, echo = TRUE} -->
<!-- raw_data_df <- read_csv( -->
<!-- here("data", "raw_records.csv") -->
<!-- ) -->
<!-- ``` -->
## `renv`
<center>
![](img/renv.png){width="400"}
[Read this](https://rstudio.github.io/renv/).
</center>
## `renv` demonstration
## `renv` demonstration
1. Create a project file
2. `renv::init()`
3. Do some stuff
4. `renv::snapshot()`
5. Share with someone
6. `renv::restore()`
7. Do some other stuff
8. Go to point 4...
## A low-effort alternative
<br>
Saving your **session info** is the **least** we can do!
<br>
<br>
```{r, eval = F, echo = T}
writeLines(capture.output(sessionInfo()), "sessionInfo.txt")`
```
<!-- ## A (better?) alternative: `rix` -->
<!-- <br> -->
<!-- New (to me) but claims to offer advantages over `renv`. -->
<!-- <br> -->
<!-- Have [a read](https://cran.r-project.org/web/packages/rix/index.html) or [watch a tutorial](https://www.youtube.com/watch?v=tM4JrCWZpwA) to find out more. -->
## Quarto
<br>
```{r}
effiency_number <- 200
```
Using Quarto allows you to make cool documents (and slideshows) while automating your results, making you approximately `r effiency_number`% more efficient.
## Quarto
<br>
```{r}
effiency_number <- 200
```
Using Quarto allows you to make cool documents (and slideshows) while automating your results, making you approximately `r effiency_number`% more efficient.
![](img/quarto.png){width="1000"}
## Quarto
<br>
```{r}
effiency_number <- 200
```
Using Quarto allows you to make cool documents (and slideshows) while automating your results, making you approximately `r effiency_number`% more efficient.
![](img/quarto.png){width="1000"}
It also makes everything [look better](https://quarto.org/docs/gallery/).
## Summary
::: columns
::: {.column width="50%"}
DOs
- Script **everything**\
- Use project files
- Use `renv` to manage package versions
- Use Quarto
:::
::: {.column width="50%"}
DON'Ts
- Use `setwd()`
- Save workspaces
- Manually copy results
:::
:::
## Extras
### Fundamentals:
- Documentation (e.g., README, comments)
- Linear scripts
- Function conflicts
### Bonus points:
- `here` package
- Version control (e.g., GitHub)
## Advertisements!
<center>
<br>
::: columns
::: {.column width="50%"}
![](img/codecheck_logo.svg){width="400" fig-align="center"}
Upcoming event [in Rotterdam](https://codecheck.org.uk/nl/workshop3.html).
:::
::: {.column width="50%"}
![](img/NLRN.png){width="400" fig-align="center"}
Dutch Reproducibility Network event [in Groningen](https://reproducibilitynetwork.nl/event/nlrnsymposium2024/).
:::
:::
</center>
## Thanks for listening!
<br>
<center>
#### Questions? Suggestions? Comments?
<br>
#### Slides
[https://github.com/langtonhugh/reprod_r]()
<br>
#### Contact
s.h.langton\@amsterdamumc.nl
[www.samlangton.info](www.samlangton.info)