-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall-packages.R
executable file
·62 lines (52 loc) · 1.43 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
#!/usr/bin/Rscript
require(yaml)
# get installed packages
i.pkgs <- rownames(installed.packages())
# packages on CRAN
a.pkgs <- read_yaml("install.yaml")
n.pkgs <- a.pkgs[["CRAN"]]
# 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 github packages
if (!require("devtools")) install.packages("devtools")
devtools::install_github("talgalili/d3heatmap")
# 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)