-
Notifications
You must be signed in to change notification settings - Fork 1
/
reprohack_22may2024.qmd
301 lines (186 loc) · 4.63 KB
/
reprohack_22may2024.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
---
title: "Reproducible workflows in R"
author: "Sam Langton -- Amsterdam UMC"
date: "22 May, 2024"
format:
revealjs:
auto-stretch: false
editor: visual
editor_options:
chunk_output_type: console
date-format: long
---
## Who am I?
::: columns
::: {.column width="60%"}
- Software/data consultant in RDM
- Research background: spatial patterning of crime
- R enthusiast
- Here to make reproducibility easier!
:::
::: {.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>
:::
:::
## Reproducibility: why bother?
- Yourself
- Your collaborators
- The scientific community
- Stakeholders (e.g., the public)
## Tell me!
<br> <br>
<center>
Why does your (or your colleagues') code break?
## Tell me!
<br> <br>
<center>
Have you ever ended up with different results to the last run?
<Br>
Did you know why?
<!-- ## Tell me! -->
<!-- <br> <br> -->
<!-- <center>How do you ~~ensure~~ maximize the chances that your analyses are reproducible?</center> -->
##
<center>![](img/drake.png){width="800"}</center>
## Focus your energy
1. Project folders
2. Options in RStudio
3. The `here` package
4. `renv`
5. Quarto
## 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. Do some stuff
3. `renv::init()`
4. Do some more stuff
5. `renv::snapshot()`
6. Share with someone
7. `renv::restore()`
8. Do some other stuff
9. Go to point 5...
## 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://github.com/danieltomasz/hikmah-academic-quarto?tab=readme-ov-file).
## Summary
::: columns
::: {.column width="50%"}
DOs
- Use project files
- Use `here` for working directories
- Use `renv` to manage package versions
- Use Quarto
:::
::: {.column width="50%"}
DON'Ts
- Use `setwd()`
- Save workspaces
- Manually copy results
:::
:::
## Thanks for listening!
<br>
<br>
<center>
Questions? Suggestions? Want advice?
<br>
Slides: [https://github.com/langtonhugh/reprod_r]()
<br>
Sam Langton
s.h.langton\@amsterdamumc.nl
[www.samlangton.info](www.samlangton.info)
## Extras
#### Assumed:
- Script *everything* ([De Graaff., 2021](https://www.dropbox.com/s/vn7rn9m5ht2miol/reproducibility.pdf?e=1&dl=0))
- Documentation
- Linear scripts
- Function conflicts
- Comment your code
#### Bonus points:
- Version control (e.g., GitHub)