-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall_dependencies.R
56 lines (41 loc) · 1.55 KB
/
install_dependencies.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
#!/usr/bin/Rscript
repos <- "https://ftp.acc.umu.se/mirror/CRAN/"
dir.create("vendor", showWarnings = FALSE)
dir.create("vendor_cache", showWarnings = FALSE)
.libPaths("vendor")
if (!require("devtools", lib = "vendor")) {
install.packages("devtools", lib = "vendor", repos=repos)
stopifnot(require("devtools", lib = "vendor"))
}
deps <- read.csv("dependencies.csv", stringsAsFactors = FALSE)
install_dep <- function(pkg, version, repo, lib = NULL) {
if (is.character(lib)) {
dir.create(lib, showWarnings = FALSE)
}
ip <- installed.packages(lib = lib)
if (!pkg %in% row.names(ip)) {
if (repo == "bioc") {
source("https://bioconductor.org/biocLite.R")
biocLite(pkg, lib = lib, destdir="vendor_cache")
return(TRUE)
}
install_version(pkg, version = version, type = "source", lib = lib, repos = repos, destdir="vendor_cache")
return(TRUE)
}
have_version <- ip[pkg, "Version"]
if (version == have_version || repo == "bioc") {
return(TRUE)
}
if (is.null(lib)) {
return(FALSE) # Don't overwrite existing package in default lib
}
install_version(pkg, version = version, type = "source", lib = lib, repos = repos, destdir="vendor_cache")
}
for (i in 1:nrow(deps)) {
install_dep(deps$package[i], deps$version[i], deps$repo[i], lib = "vendor")
}
missing_packages <- setdiff(deps$package, row.names(installed.packages(lib = "vendor")))
if (length(missing_packages) > 0) {
stop(paste("failed to install packages:", paste(missing_packages, collapse = ", ")))
}
message("All dependencies installed successfully")