-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession8.Rmd
265 lines (180 loc) · 5.9 KB
/
session8.Rmd
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
---
title: "Introduction to the {targets} package"
subtitle: "Reproducible Scientific Workflows in R"
author:
- "Ernest Guevarra"
date: '2024-02-05'
output:
xaringan::moon_reader:
css: xaringan-themer.css
nature:
slideNumberFormat: "%current%"
highlightStyle: github
highlightLines: true
ratio: 16:9
countIncrementalSlides: true
---
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
knitr::opts_chunk$set(
fig.width=9, fig.height=3.5, fig.retina=3,
out.width = "100%",
cache = FALSE,
echo = TRUE,
message = FALSE,
warning = FALSE,
hiline = TRUE
)
if (!require(remotes)) install.packages("remotes")
if (!require(fontawesome)) remotes::install_github("rstudio/fontawesome")
if (!require(tweetrmd)) remotes::install_github("gadenbuie/tweetrmd")
if (!require(webshot2)) remotes::install_github("rstudio/webshot2")
```
```{r xaringan-themer, include=FALSE, warning=FALSE}
library(xaringanthemer)
style_mono_light(
base_color = "#002147",
title_slide_background_image = "",
title_slide_background_size = "cover",
header_font_google = google_font("Fira Sans"),
text_font_google = google_font("Fira Sans Condensed"),
text_font_size = "1.2em",
link_color = "#214700",
header_h1_font_size = "50px",
header_h2_font_size = "40px",
header_h3_font_size = "30px",
code_font_google = google_font("Fira Mono"),
text_slide_number_font_size = "0.5em",
footnote_font_size = "0.5em"
)
```
class: inverse, middle
.pull-left[
Masons, when they start upon a building,
Are careful to test out the scaffolding;
Make sure that planks won't slip at busy points,
Secure all ladders, tighten bolted joints.
And yet all this comes down when the job's done
Showing off walls of sure and solid stone.
]
.pull-right[
So if, my dear, there sometimes seem to be
Old bridges breaking between you and me
Never fear. We may let the scaffolds fall
Confident that we have built our wall.
- "Scaffolding" by Seamus Heaney, 1939-2013
]
---
# Outline
* Concepts on scientific workflows
* The `{targets}` package
* Practical session
---
class: inverse, center, middle
# Concepts on scientific workflows
---
class: inverse, center, middle
# Concept #1: Reproducibility, reproducibility, reproducibility!
---
class: center, middle
```{r tweet1, echo = FALSE, eval = FALSE}
tweetrmd::tweet_screenshot(
tweet_url("kwbroman", "667735926915731457"),
hide_media = TRUE,
theme = "dark"
)
```
# Most important tool for Reproducible Research is the mindset, when starting, taht the end product will be reproducible.
[Keith Baggerly](http://odin.mdacc.tmc.edu/~kabaggerly/), via [@kwbroman](https://twitter.com/kwbrowman) [tweet](https://twitter.com/kwbroman/status/667735926915731457)
---
class: inverse, center, middle
# Concept #2: Organisation
---
class:: center, middle
# File organization and naming are powerful weapons against chaos.
[@JennyBryan](https://twitter.com/jennybryan)
---
background-color: #FFFFFF
background-image: url(images/file_organisation.png)
background-size: 90%
---
class: inverse, center, middle
# Concept #3: DRY - Don't repeat yourself
---
class: center, middle
# Don't repeat yourself. It's not only repetitive, it's redundant, and people have heard it before.
Lemony Snicket
---
class: center, middle
# "You should consider writing a function whenever you’ve copied and pasted a block of code more than twice (i.e. you now have three copies of the same code)"
---
class: inverse, center, middle
# Challenges with scientific workflows
---
# Sisyphean loop
.pull-left[
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/58/Nekyia_Staatliche_Antikensammlungen_1494_n2.jpg/582px-Nekyia_Staatliche_Antikensammlungen_1494_n2.jpg" width="450px" style="vertical-align:middle" />
]
.pull-right[
1. Launch the code.
2. Wait while it runs.
3. Discover an issue.
4. Restart from scratch.
]
---
# The `{targets}` package
.pull-left[
<img src="https://github.com/ropensci/targets/raw/main/man/figures/logo.png" width="400px" style="vertical-align:middle" />
]
.pull-right[
* a pipeline toolkit for Statistics and data science in R
* maintain a reproducible workflow without repeating yourself
* learns how your workflow fits together
* skips costly runtime for tasks that are already up-to-date
* runs only the necessary computation
* supports implicit parallel computing
* abstracts files as R objects
* shows tangible evidence that the results match the underlying code and data
]
---
# `{targets}` file organisation
.pull-left[
.center[![](images/targets_file_organisation.png)]
]
.pull-right[
* this is a typical file structure with user-defined components of any project-oriented workflow
* the `_targets.R` file, however, is special and specific to a `{targets}` workflow - it is the target script file
* the target script file should be in the project's root directory
]
---
# `{targets}` script file
.pull-left[
.center[![](images/target_script.png)]
]
.pull-right[
* Load the packages required (1)
* Load custom functions (1)
* Define individual targets - intermediate step of the workflow (2)
* End with a list of targets objects
]
---
background-color: #FFFFFF
background-image: url(images/workflow.png)
background-size: 60%
# `{targets}` workflow
---
class: inverse, center, middle
# Questions?
---
class: inverse, center, middle
# Practical session
## We will all continue to go through Exercise #1 in the [Practical R for Epidemiologists](https://practical-r.org/exercise1.html) book
---
class: inverse, center, middle
# Questions?
---
class: inverse, center, middle
# Thank you!
Slides can be viewed at https://oxford-ihtm.io/open-reproducible-science/session8.html
PDF version of slides can be downloaded at https://oxford-ihtm.io/open-reproducible-science/pdf/session8-reproducible-scientific-workflows.pdf
R scripts for slides available [here](https://github.com/OxfordIHTM/open-reproducible-science/blob/main/session8.Rmd)