-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall_cran_pkgs.R
executable file
·375 lines (357 loc) · 6.92 KB
/
install_cran_pkgs.R
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
374
375
#!/usr/bin/env Rscript
# Script that installs additional packages from CRAN
# Takes in the distribution as the first argument.
args <- commandArgs(trailing = TRUE)
distribution <- args[1]
# Set official mirror for CRAN
options(repos = c("https://cloud.r-project.org/"))
# Packages that are already in the image
# but must be reinstalled to the latest versions
reinstall_with_newer_version <- c(
"Matrix"
)
# Shared packages that must be installed from source
# for compatability purposes
shared_pkgs_install_from_src <- c(
"TMB"
)
# CRAN packages to install from source, per distro
cran_pkgs_from_src <- list(
rstudio = shared_pkgs_install_from_src,
`rstudio-local` = shared_pkgs_install_from_src
)
# Pharmaverse R packages
pharmaverse_pkgs <- c(
"admiral",
"admiral.test",
"admiraldev",
"admiralonco",
"admiralophtha",
"formatters",
"rtables",
"rlistings",
"nestcolor",
"teal",
"teal.code",
"teal.data",
"teal.logger",
"teal.modules.clinical",
"teal.modules.general",
"teal.reporter",
"teal.slice",
"teal.transform",
"teal.widgets",
"tern",
"mmrm"
)
# Regular CRAN packages to install
shared_pkgs <- c(
"assertthat",
"bayesplot",
"BayesPPD",
"bbmle",
"bdsmatrix",
"bigD",
"binom",
"bookdown",
"broom",
"broom.helpers",
"callr",
"car",
"checkmate",
"chk",
"circlize",
"cli",
"cobalt",
"colourpicker",
"covr",
"cowplot",
"crayon",
"DBI",
"DescTools",
"deSolve",
"devtools",
"dfoptim",
"DiagrammeR",
"diffdf",
"digest",
"dm",
"dplyr",
"duckdb",
"DT",
"emmeans",
"EnvStats",
"fastGHQuad",
"flexsurv",
"flextable",
"forcats",
"formatters",
"formula.tools",
"fs",
"gbm",
"gdtools",
"geeasy",
"geepack",
"GenSA",
"gert",
"GGally",
"ggExtra",
"ggfortify",
"ggiraph",
"ggmosaic",
"ggnewscale",
"ggplot2",
"ggpmisc",
"ggpubr",
"ggrepel",
"gh",
"git2r",
"glmmTMB",
"globals",
"glue",
"goftest",
"gridExtra",
"gt",
"gtable",
"gtsummary",
"here",
"htmltools",
"httr",
"huxtable",
"igraph",
"jsonlite",
"juicyjuice",
"kableExtra",
"knitr",
"labeling",
"lifecycle",
"lintr",
"lme4",
"lmerTest",
"lmtest",
"logger",
"maditr",
"magick",
"magrittr",
"markdown",
"MatchIt",
"matrixcalc",
"mcr",
"mockery",
"mstate",
"muhaz",
"nloptr",
"nomnoml",
"nortest",
"odbc",
"officer",
"operator.tools",
"optimx",
"oysteR",
"pak",
"parglm",
"patchwork",
"pbkrtest",
"pillar",
"pkgdown",
"png",
"purrr",
"quarto",
"r2rtf",
"R6",
"randomForest",
"rbmi",
"rcmdcheck",
"Rcpp",
"RcppNumerical",
"RcppProgress",
"Rdpack",
"readr",
"readxl",
"remotes",
"renv",
"reticulate",
"rjags",
"rJava",
"RJDBC",
"rlang",
"rmarkdown",
"roxylint",
"roxytypes",
"rstan",
"rstantools",
"rstpm2",
"rsvg",
"rvest",
"scales",
"shiny",
"shinyjs",
"shinyRadioMatrix",
"shinytest",
"shinytest2",
"shinyTree",
"shinyvalidate",
"shinyWidgets",
"shinylive",
"simsurv",
"sparkline",
"spelling",
"ssh",
"statmod",
"stringi",
"styler",
"survminer",
"table1",
"testthat",
"tibble",
"tidyr",
"tidyselect",
"tinytest",
"tinytex",
"tfrmt",
"tzdb",
"uuid",
"V8",
"vdiffr",
"viridisLite",
"vistime",
"vroom",
"webshot",
"WeightIt",
"withr",
"xfun",
"xml2",
"yaml"
)
# Local development helper packages
local_dev_packages <- c(
"diffviewer",
"languageserver"
)
# Collate all packages
cran_pkgs <- list(
rstudio = c(
shared_pkgs,
pharmaverse_pkgs
),
`rstudio-local` = c(
shared_pkgs,
pharmaverse_pkgs,
local_dev_packages
),
`gcc13` = shared_pkgs[!shared_pkgs %in% c("rjags")],
`gcc14` = shared_pkgs[!shared_pkgs %in% c("rjags")],
`atlas` = shared_pkgs[!shared_pkgs %in% c("rjags")],
`valgrind` = shared_pkgs[!shared_pkgs %in% c("rjags")],
`intel` = shared_pkgs[!shared_pkgs %in% c("rjags")],
`nosuggests` = shared_pkgs[!shared_pkgs %in% c("rjags")],
`mkl` = shared_pkgs[!shared_pkgs %in% c("rjags")]
)
# Re-install packages with newer versions
install.packages(
reinstall_with_newer_version,
type = "source",
Ncpus = parallel::detectCores()
)
# Get diff of installed and uninstalled packages for
# idempotent package installation
new_pkgs_from_src <- cran_pkgs_from_src[[distribution]][
!(cran_pkgs_from_src[[distribution]] %in% installed.packages()[, "Package"])
]
# Install "source only" packages from source
if (length(new_pkgs_from_src)) {
install.packages(
new_pkgs_from_src,
type = "source",
Ncpus = parallel::detectCores()
)
}
# Install rjags with special params for fedora distros
if (startsWith(distribution, "gcc") || distribution == "atlas" || distribution == "valgrind" || distribution == "intel" || distribution == "nosuggests" || distribution == "mkl") {
install.packages(
"rjags",
type = "source",
configure.args = "--enable-rpath",
Ncpus = parallel::detectCores()
)
}
# Get diff of installed and uninstalled packages for
# idempotent package installation
new_pkgs <- cran_pkgs[[distribution]][
!(cran_pkgs[[distribution]] %in% installed.packages()[, "Package"])
]
# Install all other packages, only if they are uninstalled on the image
if (length(new_pkgs)) {
install.packages(new_pkgs,
Ncpus = parallel::detectCores()
)
}
# Conditionally install phantonJS
if (require("shinytest")) {
shinytest::installDependencies()
file.copy(shinytest:::find_phantom(), "/usr/local/bin/phantomjs")
}
# Conditionally install TinyTex
if (require("tinytex")) {
tlmgr_packages <- c(
"makeindex",
"metafont",
"mfware",
"inconsolata",
"tex",
"ae",
"parskip",
"listings",
"xcolor",
"epstopdf-pkg",
"pdftexcmds",
"kvoptions",
"texlive-scripts",
"grfext",
"soul",
"todonotes",
"koma-script",
"subfig",
"bookmark",
"babel-english",
"caption"
)
# nolint start
# See point 5 in
# https://github.com/rbind/yihui/blob/master/content/tinytex/faq.md
tinytex_installer <- paste0('
wget -qO- "https://raw.githubusercontent.com/yihui/tinytex/master/tools/install-unx.sh" | sh -s - --admin --no-path
mv ~/.TinyTeX /opt/TinyTeX
/opt/TinyTeX/bin/*/tlmgr path add
tlmgr install ', paste(tlmgr_packages, collapse = " "), "
tlmgr path add
")
# nolint end
exit_status <- system(tinytex_installer)
cat("TinyTeX installer exited with code =", exit_status, "\n")
if (exit_status != 0) {
quit(status = exit_status)
}
tinytex::r_texmf()
permission_update <- '
chown -R root:staff /opt/TinyTeX
chmod -R g+w /opt/TinyTeX
chmod -R g+wx /opt/TinyTeX/bin
export PATH=/opt/TinyTeX/bin/x86_64-linux:${PATH}
echo "PATH=${PATH}" >> ${R_HOME}/etc/Renviron
'
exit_status <- system(permission_update)
cat("TinyTeX permission update exited with code =", exit_status, "\n")
if (exit_status != 0) {
quit(status = exit_status)
}
}
# Update all packages
tryCatch(
expr = {
update.packages(ask = FALSE)
},
error = function(e) {
print(e)
}
)