forked from ludvigla/FFPE_mouse_brain_explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-packages.R
executable file
·80 lines (69 loc) · 1.78 KB
/
install-packages.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
#!/usr/bin/Rscript
require(yaml)
## Installation Script for GeneTech course
# get installed packages
i.pkgs <- rownames(installed.packages())
# packages on CRAN
a.pkgs <- read_yaml("install.yaml")
n.pkgs <- a.pkgs[["CRAN"]]
b.pkgs <- a.pkgs[["BioConductor"]]
# to collect stats
success <- c()
fail <- c()
# install CRAN based packages
if (!(is.null(n.pkgs))) {
for (p in n.pkgs) {
# check if already installed
if (!(p %in% i.pkgs)){
# try-catch install
stat <- try(install.packages(p,
dependencies = TRUE,
repos = "https://ftp.acc.umu.se/mirror/CRAN/"))
# add status
if (!(is.null(attr(stat,"class")))) {
fail <- c(fail,p)
} else {
success <- c(success,p)
}
} else {
success <- c(success,p)
}
}
}
# install Bioconductor packages
if (!is.null(b.pkgs)) {
for (p in b.pkgs) {
# check if already installed
if (!(p %in% i.pkgs)){
# try-catch install
stat <- try(BiocManager::install(p))
# add status
if (!(is.null(attr(stat,"class")))) {
fail <- c(fail,p)
} else {
success <- c(success,p)
}
} else {
success <- c(success,p)
}
}
}
# log-message construction
success <- ifelse(is.null(success),
"NONE\n\n",
paste(success,collapse = "\n"))
fail <- ifelse(is.null(fail),
"NONE\n\n",
paste(fail,collapse = "\n")
)
txt <- paste(c("\n----\n",
"Successful installs:\n",
"----\n",
success,
"\n\n----\n",
"Failed installs:\n",
"----\n",
fail),
collapse = "")
# print summary message
cat(txt)