#!/usr/bin/Rscript # ---------------------------------------------------------------------------- # # Parsing script parameters # # ---------------------------------------------------------------------------- # # Getting script params args <- commandArgs(trailingOnly = TRUE) if(length(args) < 1) { stop("You must specify the vCPU count") } if(length(args) > 2) { stop("You specified too many arguments") } # Getting vCPUs count cpu_count <- args[1] # Should be {{ ansible_processor_vcpus }} cat(paste("Running with", cpu_count, "vCPUs.\n")) # Getting library path if(length(args) > 1) { library_path <- args[2] # Should be "{{ r_library_dir }}" } else { library_path <- .libPaths() } cat(paste("Using", library_path, "as R library.\n")) # ---------------------------------------------------------------------------- # # Helper functions definition # # ---------------------------------------------------------------------------- # # Defining a helper function to check for missing packages missing.packages <- function(required) { return(required[!(required %in% installed.packages(lib.loc=library_path)[,"Package"])]) } # ---------------------------------------------------------------------------- # # CRAN based packages installation # # ---------------------------------------------------------------------------- # cat("----------------------------------------------------------------------\n") # Listing required packages from CRAN required.packages <- c("reshape2", "ggplot2", "data.table", "Cairo", "snowfall", "gplots", "foreach", "doParallel", "jsonlite", "zoo") cat("Required packages from CRAN:\n") print(required.packages) # Checking for missing packages new.packages <- missing.packages(required.packages) # Installing missing packages if(length(new.packages)) { cat("The following packages are missing and will be installed:\n") print(new.packages) install.packages(new.packages, lib=library_path, Ncpu=cpu_count) } else { cat("++ All CRAN packages already installed.\n") } # Checking if some packages couldn't be installed anyway if(length(missing.packages(required.packages))) { warning('++ Some packages from CRAN could not be installed') quit(1) } # ---------------------------------------------------------------------------- # # Bioconductor based packages installation # # ---------------------------------------------------------------------------- # cat("----------------------------------------------------------------------\n") # Sourcing external installation script for bioconductor (bioconductor CLI) source("http://bioconductor.org/biocLite.R") # Packages to install from the bioconductor repository required.packages <- c("impute", "multtest", "CGHbase", "edgeR", "snpStats", "GO.db", "preprocessCore", "AnnotationDbi", "limma") cat("Required packages from Bioconductor:\n") print(required.packages) # Checking for missing packages new.packages <- missing.packages(required.packages) # If there are some packages to be installed if(length(new.packages)) { cat("The following packages are missing and will be installed:\n") print(new.packages) biocLite(new.packages) } else { cat("++ All Bioconductor packages already installed.\n") } # Checking if some packages couldn't be installed anyway if(length(missing.packages(required.packages))) { warning('++ Some packages from Bioconductor could not be installed') quit(1) } # ---------------------------------------------------------------------------- # # CRAN packages with dependencies from bioconductor # # ---------------------------------------------------------------------------- # cat("----------------------------------------------------------------------\n") # Packages that require previous packages to be installed required.packages <- c("WGCNA") cat("Required packages from CRAN with dependencies:\n") print(required.packages) # Checking for missing packages new.packages <- missing.packages(required.packages) # Installing missing packages if(length(new.packages)) { cat("The following packages are missing and will be installed:\n") print(new.packages) install.packages(new.packages, lib=library_path, Ncpu=cpu_count) } else { cat("++ All CRAN packages with dependencies already installed.\n") } # Checking if some packages couldn't be installed anyway if(length(missing.packages(required.packages))) { warning('++ Some packages from CRAN could not installed') quit(1) } # ---------------------------------------------------------------------------- # # Custom packages installed from source # # ---------------------------------------------------------------------------- # cat("----------------------------------------------------------------------\n") # Packages to be installed from source required.packages <- new.env() required.packages$CGHtest <- "http://files.thehyve.net/CGHtest_1.1.tar.gz" required.packages$CGHtestpar <- "http://files.thehyve.net/CGHtestpar_0.0.tar.gz" cat("Required custom packages:\n") print(ls(required.packages)) # Checking for missing packages new.packages <- missing.packages(ls(required.packages)) # Installing package from source if(length(new.packages)) { cat("The following packages are missing and will be installed:\n") print(new.packages) for(pkg in new.packages) { install.packages(required.packages[[pkg]], repos=NULL, lib=library_path, Ncpu=cpu_count) } } else { cat("++ All custom packages already installed.\n") } # Checking if some packages couldn't be installed anyway if (length(missing.packages(ls(required.packages)))) { warning('++ Some custom packages could not be installed.') quit(1) } cat("Done\n") quit(status=0)