Skip to content
Snippets Groups Projects
Commit 7f8af77c authored by thierry Balliau's avatar thierry Balliau
Browse files

ajout script install v0.6.15 test dockerfile ok

parent 883143f1
No related branches found
No related tags found
No related merge requests found
### Script d'installation de MCQR
## internal variable to modify depending on R version and current mcqr version
Rminrequirement <- "3.6.0"
packagesForOldVersion <- list()
packagesForOldVersion$R36 <- list()
packagesForOldVersion$R36 = list(c("name" = "caTools", "version" = "1.17.1.4"),c("name" = "quantreg", "version" = "5.85"))
packages = c("car", "cpp11", "stringr", "readODS", "VIM", "ade4", "gplots", "clValid", "agricolae", "ggplot2", "RColorBrewer", "plotly", "plyr", "dplyr", "data.table", "nlme", "ggVennDiagram", "dataverse")
## internal function to ask for valdiation
## inspired from https://stackoverflow.com/questions/27112370/make-readline-wait-for-input-in-r
askValid <- function(){
raw <- "this is not a valid answer"
if(interactive()){
while(!(raw %in% c("n", "y", ""))){
raw <- readline("continue? (y/n (default y): ")
}
} else{
# non-interactive
while(!(raw %in% c("n", "y", ""))){
cat("continue? (y/n (default y): ");
raw <- readLines("stdin",n=1);
}
}
if (raw == "n"){
validation <- F
} else {
validation <- T
}
return(validation)
}
checkLibrary <- function(libraries){
result = TRUE
installedPackages<- rownames(installed.packages())
for(mylib in libraries){
if(!(mylib %in% installedPackages)){
result = FALSE
}
}
return(result)
}
checkLibraryAndInstallIt <- function(libraries){
result = TRUE
installedPackages<- rownames(installed.packages())
for(mylib in libraries){
if(!(mylib %in% installedPackages)){
install_version(mylib['name'], mylib['version'])
}
}
return(result)
}
checkPackageAndInstallIt <- function(libraries, osName){
result = TRUE
installedPackages<- rownames(installed.packages())
for(mylib in libraries){
if(!(mylib %in% installedPackages)){
cat(paste0("installing ", mylib, " Package\n"))
if (osName=="windows"){
install.packages(mylib, type="binary", quiet=TRUE)
}else{
install.packages(mylib, quiet=TRUE)
}
## test if library can be loaded
tryCatch({
suppressPackageStartupMessages(library(mylib,character.only=TRUE))
}, error = function(e) {
cat(paste0("Error library ", mylib, " can't be installed\n"))
result = FALSE
}, finally = {
detach(paste0("package:", mylib), unload = TRUE, character.only=TRUE)
cat(paste0("library ", mylib, " Successfully installed\n"))
})
}else{
cat(paste0(mylib, " Package is already installed, skip it\n"))
}
}
return(result)
}
install_MCQR <- function(prepare=FALSE){
# Check environnment
os <- Sys.info()
cat("Operating System\n")
cat(paste0(os['sysname'], " ", os['release'], " ", os['version'], "\n"))
cat(paste0("Machine type : ", os['machine'], "\n"))
### checking R version for listing of necessary packages
RVersion <- R.Version()
cat(paste0(RVersion$version.string, "\n"))
## specific installation depending on R version
if(as.integer(RVersion$major)<4){
if(as.integer(RVersion$major)<3){
stop(cat(paste0("Sorry your R version is too old for the MCQR Package, the minimum requirement is R version",Rminrequirement, "\n")))
}else{
if(as.double(RVersion$minor <0.6)){
stop(cat(paste0("Sorry your R version is too old for the MCQR Package, the minimum requirement is R version",Rminrequirement, "\n")))
}else{
## check if dependancies can be loaded
if(suppressWarnings(!checkLibrary(packagesForOldVersion$R36))){
cat("need some old version of package\n")
cat("installing remote package to get package from cran archive and load it\n")
install.packages("remotes")
library(remotes)
suppressWarnings(checkLibraryAndInstallIt(packagesForOldVersion$R36))
detach("package:remotes", unload=TRUE)
}else{
cat("no need special install\n")
}
}
}
}else{
cat("no need special install\n")
}
## check and install needed packages
cat("for windows install prefer binary install instead of source install\n")
test = checkPackageAndInstallIt(packages, os["sysname"])
if(!prepare){
#Install MCQR
if("MCQR" %in% rownames(installed.packages())){
cat("MCQR was already installed. Removing it\n")
remove.packages("MCQR")
}
cat("Installing latest version of MCQR\n")
install.packages('https://forgemia.inra.fr/pappso/mcqr/uploads/215fb1480c4f47375f3fd1366354ef5b/MCQR_0.6.15.tar.gz', repos = NULL, type = 'source')
}
}
install_MCQR(FALSE)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment