-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdependencies.Rmd
More file actions
287 lines (172 loc) · 4.6 KB
/
Copy pathdependencies.Rmd
File metadata and controls
287 lines (172 loc) · 4.6 KB
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
---
title: 'Controlling dependencies'
# subtitle: 'Nice subtitle here'
author: 'Francisco Rodriguez-Sanchez'
institute: 'https://frodriguezsanchez.net'
# date: '@frod_san'
fontsize: 10pt
output:
binb::metropolis:
keep_tex: no
pandoc_args: ['--lua-filter=hideslide.lua']
urlcolor: blue
linkcolor: blue
header-includes:
- \definecolor{shadecolor}{RGB}{230,230,230}
# - \setbeamercolor{frametitle}{bg=black}
---
```{r include=FALSE, cache=FALSE}
library('knitr')
### Chunk options ###
## Text results
opts_chunk$set(echo = TRUE, eval = FALSE, warning = FALSE, message = FALSE, size = 'tiny')
opts_template$set(fig = list(echo = FALSE, eval = TRUE))
## Code decoration
opts_chunk$set(tidy = FALSE, comment = NA, highlight = TRUE, prompt = FALSE, crop = TRUE)
# ## Cache
# opts_chunk$set(cache = TRUE, cache.path = 'knitr_output/cache/')
# ## Plots
# opts_chunk$set(fig.path = 'knitr_output/figures/')
opts_chunk$set(fig.align = 'center', out.width = '80%')
### Hooks ###
## Crop plot margins
knit_hooks$set(crop = hook_pdfcrop)
## Reduce font size
## use tinycode = TRUE as chunk option to reduce code font size
# see http://stackoverflow.com/a/39961605
knit_hooks$set(tinycode = function(before, options, envir) {
if (before) return(paste0('\n \\', options$size, '\n\n'))
else return('\n\n \\normalsize \n')
})
```
---
```{r opts.label='fig', out.width='70%'}
include_graphics('images/sotobosque.png')
```
---
\Large
Updating R packages broke your script?
Need to run an old script from you, or someone else?
How to reproduce your analysis in a year, \newline or different computer?
## `sessionInfo` records OS & used packages
\tiny
```{r eval=T}
sessionInfo()
```
## `checkpoint` recreates R packages in given date
\footnotesize
```{r }
library('checkpoint')
options(checkpoint.mranUrl="https://packagemanager.posit.co/")
checkpoint('2024-10-08')
source('analysis.R')
```
\normalsize
1. Detects packages used
2. Installs version from given date (only CRAN)
3. Independent install (not messing w/ main library)
## `automagic` records & install packages (CRAN + GitHub)
\scriptsize
```{r }
automagic::make_deps_file()
```
File `deps.yaml` records dependencies:
\tiny
```yaml
- Package: equatiomatic
Repository: CRAN
Version: 0.1.0
- Package: report
GithubUsername: easystats
GithubRepo: report
GithubRef: HEAD
GithubSHA1: c48a4bb0a40df7116bc502aa3ce2cbbc9d70b7e2
```
\scriptsize
To install all those dependencies:
```{r eval=FALSE, echo=TRUE}
automagic()
```
## `groundhog` loads packages as available on given date
https://groundhogr.com/
```{r eval=FALSE, echo=TRUE}
library('groundhog')
groundhog.library(pkg = c('dplyr', 'ggplot2'),
date = "2024-09-01")
```
## `renv`: recommended way to control dependencies
```{r }
renv::init()
# Create private package library for project
renv::snapshot()
# Capture dependencies in lockfile
renv::restore()
# Regenerate dependencies from lockfile
```
https://rstudio.github.io/renv/
---
\Large
To ensure reproducibility,
besides R packages
we also need to control
**computational environment**
---
\large
`Docker` recreates virtual systems
from a `Dockerfile`
## `rang` recreates environment (pkgs + external software)
https://gesistsa.github.io/rang/
```{r opts.label='fig', out.width='90%'}
include_graphics('images/rang.png')
```
## `liftr`: process Rmd in Docker container
```{r opts.label='fig', out.width='95%'}
include_graphics('images/liftr.png')
```
\footnotesize https://liftr.me/
## `containerit` creates Dockerfile
```{r }
library('containerit')
dockfile <- dockerfile(from = 'mypaper.Rmd')
```
\footnotesize https://o2r.info/containerit
## `tugboat` creates Dockerfile w/ entire software environment
```{r opts.label = 'fig'}
include_graphics('images/tugboat.png')
```
```{r echo=TRUE, eval=FALSE}
library(tugboat)
create()
build()
```
https://www.dmolitor.com/tugboat/
::: hide :::
## `holepunch`: reproduce analysis in the cloud (Binder)
```{r opts.label = 'fig'}
include_graphics('images/holepunch.png')
```
\footnotesize https://karthik.github.io/holepunch/
:::
## `rix`: reproducible environments with Nix
https://docs.ropensci.org/rix/
```{r opts.label = 'fig'}
include_graphics('images/rix.png')
```
## Remember to cite software used!
https://pakillo.github.io/grateful/
```{r}
library('grateful')
cite_packages()
```
```{r opts.label = 'fig'}
include_graphics('images/grateful.png')
```
# Your turn
---
\Large
- Create script/Rmd using different packages
- Call `checkpoint` on former date
- Record dependencies:
- `renv::snapshot`
- Recreate packages
- `restore()`