-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_packages.R
50 lines (43 loc) · 1.74 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
required_packages <- function(required) {
if(missing(required)) {
required <- c(
# tidyverse
"tidyverse",
# Rstudio
"rmarkdown",
# W3 packages
"tinytex", "pander", "kableExtra", "remotes",
# biometryassist
"biometryassist"
)
}
if(Sys.info()[['sysname']]!="Linux") {
oo <- options(install.packages.compile.from.source = "never")
on.exit(options(oo))
}
installed <- rownames(installed.packages())
notInstalled <- setdiff(required, installed)
if (length(notInstalled) > 0){
message("Installing required packages...\n")
install.packages(notInstalled, quiet = TRUE,
Ncpus = getOption("Ncpus", max(parallel::detectCores() - 2, 1)))
installed <- rownames(installed.packages()) # Update to see what's there now
missingPackages <- setdiff(required, installed)
if (length(missingPackages) > 0){
invisible(sapply(missingPackages,
function(x){
warning("\nThe package ", x, " has not installed sucessfully.\n",
"Please copy and paste the code:\n\n\t install.packages('", x,
"')\n\n and try running it again on the console. \n\n
If that fails again, please email the output to [email protected]\n")
}))
stop("Installation unsuccessful.")
}
else{
message("All required packages have been installed.\n")
}
}
else {
message("\nRequired packages are installed.\n")
}
}