-
Notifications
You must be signed in to change notification settings - Fork 8
/
verify_dependency_installation.R
executable file
·87 lines (59 loc) · 1.91 KB
/
verify_dependency_installation.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
#if(!require(devtools))
# install.packages("devtools")
# install.packages("lubridate")
require(devtools)
# 1. Find missing packages ----------
p <- c()
for (f in list.files(pattern = "Rmd$")) {
t <- readLines(f)
p <- unique(c(p, t[grepl("^(library|require)", t)]))
}
p <- gsub("library|require|\\(|\\)", "", p)
p <- gsub("\"", "", p)
m <- p[!p %in% installed.packages()[, 1]]
if (!length(m)) {
message("All necessary packages are installed.")
} else {
message("Missing Packages : ", paste0(m, collapse = ", "))
}
# 2. Install missing packages (CRAN ou GitHub) ----------------
thru_github <- c("lubridate", #"questionr",
"JLutils", "labelled")
#repo_github <- c("hadley", "juba", "larmarange", "larmarange")
#for (i in m[m %in% thru_github])
# install_github(i, username = repo_github[which(thru_github == i)])
for (i in m[!m %in% thru_github])
install.packages(i, dependencies = TRUE)
if (any(!p %in% installed.packages()[, 1]))
warning("Some packages installation failed.")
# 3. Manually verify certain packages --------------
library(lubridate)
if (!exists("time_length"))
install_github("hadley/lubridate")
#library(questionr)
#if (is.null(getS3method("odds.ratio", "numeric", TRUE)))
# install_github("juba/questionr")
# 4. identify mininal required version of R ---------------
#' @source http://stackoverflow.com/a/30600526/635806
min_r <- function(packages) {
req <- NULL
for (p in packages) {
# get dependencies for the package
dep <- packageDescription(p, fields = "Depends")
if (!is.na(dep)) {
dep <- unlist(strsplit(dep, ","))
r.dep <- dep[grep("R \\(", dep)]
if (!length(r.dep))
r.dep <- NA
} else {
r.dep <- NA
}
if (!is.na(r.dep))
req <- c(req, r.dep)
}
return(req)
}
v = min_r(p)
v = gsub("\\s?R\\s\\(>=\\s|\\)", "", v)
v = sort(v)[length(sort(v))]
message(" R version required is ", v, " or more recent.")