-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathgl.install.vanilla.dartR.r
243 lines (214 loc) · 7.93 KB
/
gl.install.vanilla.dartR.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#' Installs all required packages for using all functions
#' available in dartR
#'
#' The function compares the installed packages with the the currently available
#' ones on CRAN. Be aware this function only works if a version of dartR is
#' already installed on your system. You can choose if you also want to have a
#' specific version of dartR installed ('CRAN', 'master', 'beta' or 'dev' ). 'master'
#' , 'beta' and 'dev' are installed from Github. Be aware that the dev version from github is
#' not fully tested and most certainly will contain untested functions.
#' @param flavour The version of R you want to install. If NULL
#' then only packages needed for the current version will be installed. If
#' 'CRAN' current CRAN version will be installed. 'master' installs the GitHub
#' master branch, 'beta' installs the latest stable version, and 'dev' installs
#' the experimental development branch from
#' GitHub [default NULL].
#' @param verbose Verbosity: 0, silent or fatal errors; 1, begin and end; 2,
#' progress log ; 3, progress and results summary; 5, full report
#' [default 2 or as specified using gl.set.verbosity].
#' @return Returns a message if the installation was successful/required.
#' @export
#' @importFrom stringr str_trim
#' @rawNamespace import(crayon, except = c(chr, '%+%'))
#' @importFrom utils installed.packages install.packages available.packages
#' @author Custodian: Bernd Gruber (Post to
#' \url{https://groups.google.com/d/forum/dartr})
gl.install.vanilla.dartR <- function(flavour = NULL,
verbose = NULL) {
# SET VERBOSITY
verbose <- gl.check.verbosity(verbose)
# FLAG SCRIPT START
funname <- match.call()[[1]]
utils.flag.start(func = funname,
build = "Josh",
verbose = verbose)
# ERROR CHECKING
# if(is.null(flavour)){
# flavour <- "CRAN"
# }
pkg <- "devtools"
if (!(requireNamespace(pkg, quietly = TRUE))) {
cat(error(
"Package",
pkg,
" needed for this function to work. Please install it.\n"
))
return(-1)
}
pkg <- "stringr"
if (!(requireNamespace(pkg, quietly = TRUE))) {
cat(error(
"Package",
pkg,
" needed for this function to work. Please install it.\n"
))
return(-1)
}
# DO THE JOB
err <- NULL
if (!is.null(flavour)) {
if (flavour == "CRAN") {
detach("package:dartR", unload = TRUE)
if (verbose >= 2) {
cat(report(" Installing dartR from CRAN (latest version)\n"))
}
install.packages("dartR")
}
if (flavour == "master") {
if (verbose >= 2) {
cat(report(" Installing dartR from github (master)\n"))
}
detach("package:dartR", unload = TRUE)
devtools::install_github("green-striped-gecko/dartR",
ref = "master",
dependencies = TRUE)
}
if (substr(flavour, 1, 3) == "dev") {
detach("package:dartR", unload = TRUE)
if (verbose >= 2) {
cat(report(" Installing dartR from github (dev)\n"))
}
devtools::install_github("green-striped-gecko/dartR",
ref = flavour,
dependencies = TRUE)
}
if (substr(flavour, 1, 4) == "beta") {
detach("package:dartR", unload = TRUE)
if (verbose >= 2) {
cat(report(" Installing dartR from github (beta)\n"))
}
devtools::install_github("green-striped-gecko/dartR",
ref = flavour,
dependencies = TRUE)
}
}
# check all depends #check all imports check all suggests
ip <- installed.packages()[, "Package"]
suggests <-
stringr::str_trim(unlist(strsplit(
packageDescription("dartR", fields = "Suggests"), ","
)))
toinstall <- suggests[!suggests %in% ip]
available <- available.packages()[, "Package"]
toinsav <- toinstall[toinstall %in% available]
# if(verbose>=2){
# cat(report(" Installing package ggtern from provisional GitHub Repository\n"))
# }
#
# #Installing package ggtern from personal github repository because it seems
# #that this package is not maintained anymore
# devtools::install_github("mijangos81/ggtern")
if (length(toinsav) > 0) {
if (verbose >= 2) {
cat(report(
" The following packages will be installed (also available on CRAN):\n"
)
)
}
if (verbose >= 2) {
cat(" ",paste0(" ",toinsav, "\n"))
}
for (ii in 1:length(toinsav)) {
install.packages(toinsav[ii])
if (verbose >= 2) {
cat(report(paste(
" Package:", toinsav[ii], "installed.\n"
)))
}
}
if (verbose >= 2) {
cat(report(
" All required packages are now installed. If still errors, update them using "
)
)
cat(code("update.packages()"))
}
if (verbose >= 2) {
cat(report(" ",paste(
"\n You have installed dartR",
packageVersion("dartR")
)
))
}
if (verbose >= 2) {
cat(report("\nHave fun using Vanilla dartR!\n"))
}
# package installed but not available
} else if (length(toinstall) > 0) {
if (verbose >= 2) {
cat(warn(
" Warning: The following packages need to be installed, but are not available via CRAN.\n Look to github or other repositories such as bioconductor.\n"
)
)
cat(" ",paste0(toinstall,"\n"))
}
if (verbose >= 2) {
cat(warn(
" Warning: If the packages qvalue and/or SNPrelate are missing run the code and then gl.install.vanilla.dartR() again\n"
)
)
}
if (verbose >= 2) {
cat(warn(
paste(
" install.packages('devtools') \n library(devtools)\n install.packages('BiocManager')\n BiocManager::install(c('SNPRelate', 'qvalue'))\n"
)
))
}
err <- TRUE
} else {
if (verbose >= 2) {
cat(
report(
" All required packages are already installed.\n If there are still errors you might need to update them using "
)
)
}
if (verbose >= 2) {
cat(code("update.packages()"))
cat("\n")
}
# if (verbose) {
# cat(report(
# paste(
# " You have installed dartR:",
# packageVersion("dartR"),"\n"
# )
# ))
# }
}
if (verbose>= 2 & is.null(err) & !is.null(flavour)) {
if (flavour != "CRAN") {
fl <-paste0("Github [", flavour, "]")
} else {
fl <-"CRAN"
cat(report(
paste(
" You have installed dartR",
packageVersion("dartR"),
"from",
fl,
"\n"
)
))
}
if (verbose>= 2) {
message(report("\n Have fun using Vanilla dartR!\n"))
}
# FLAG SCRIPT END
if (verbose > 0) {
cat(report("Completed:", funname, "\n"))
}
}
library(dartR)
}