-
Notifications
You must be signed in to change notification settings - Fork 0
/
installdeps.R
53 lines (46 loc) · 1.51 KB
/
installdeps.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
# set cran mirror
local({
r = getOption("repos")
r["CRAN"] = "https://mirror.las.iastate.edu/CRAN"
options(repos = r)
})
# function to install r-requirements.txt
# adapted from https://gist.github.com/cannin/6b8c68e7db19c4902459
installdeps <- function(file="/opt/app-root/src/r-requirements.txt", lib="/opt/app-root/src/R_libs") {
# Install packages
if(!is.null(file)) {
packages <- utils:::read.table(file, stringsAsFactors = FALSE)
packages <- packages$V1
}
if("devtools" %in% rownames(utils:::installed.packages())) {
require(devtools)
} else {
utils:::install.packages("devtools", lib=lib)
}
if("stringr" %in% rownames(utils:::installed.packages())) {
require(stringr)
} else {
utils:::install.packages("stringr", lib=lib)
}
for(package in packages) {
tmp <- strsplit(package, .Platform$file.sep)[[1]]
packageName <- tmp[length(tmp)]
# If it is not already installed...
if(!(packageName %in% rownames(utils:::installed.packages()))) {
# Try to install from known repos (CRAN)...
if(package %in% rownames(utils:::available.packages())) {
utils:::install.packages(package, lib=lib)
# Or see if we need to install from github...
} else if(grepl("^github::", package)) {
gitPkg <- strsplit(package, "::")[[1]][2]
devtools::install_github(gitPkg)
} else {
require(BiocManager)
if(length(BiocManager::available(package))>0) {
BiocManager::install(package)
}
}
}
}
}
installdeps()