# ------------------------------------------------------------------------------------------------------------------------- # # ----------------------------------------------------------------------------------------------------------------------- # # # # File Name : SetupNewInstall.r # # Last Updated Funclist : 15 Feb 2014, 1:13 AM (Saturday) # # # # Author Name : Rick Saporta # # Author Email : RickSaporta@gmail.com # # Author URL : www.github.com/rsaporta # # # # Packages Called : devtools # # Packages Used via NS : NA # # # # ----------------------------------------------------------------------------------------------------------------------- # # # # # # # # # # ----------------------------------------------------------------------------------------------------------------------- # # ------------------------------------------------------------------------------------------------------------------------- # ## MAKE SURE THAT YOU'VE UPDATED libcurl & libxml IN THE OS # sudo yum -y install libcurl* # ## TRY # sudo yum -y install libxml2.x86_64 libxml2-devel.x86_64 # sudo yum search libxml ## MAKE SURE postgresql-devel IS INSTALLED ## sudo yum -y install postgresql postgresql-devel ## TODO: Create a log file for installation allow.non_root <- FALSE ## EXPECTED INCORRECT PACKAGE NAMES these_are_not_package_names <- c("end", "pkg.nm", "Time", "ggplot", "ARM") ## BIOCONDUCTOR SOURCE if (!require("graph")) { source("http://bioconductor.org/biocLite.R") biocLite("graph", ask=FALSE) } ## FOLDER TO SOURCE dir_with_install_files <- "~rsaporta/git/misc/rscripts/!!Setup New Install/" supportFnDir <- paste0(dir_with_install_files, "/supportFns") ## CONFIRM if (!length(dir(dir_with_install_files)) || !file.exists(supportFnDir)) stop("Directory is wrong") if (!isTRUE(allow.non_root) && system("whoami", intern=TRUE) != "root") { stop("\n\nYou may want to run this having called \nsudo R --vanilla\n\n") } if (!exists("%ni%")) `%ni%` <- Negate(`%in%`) ## Shorthand for suppressPackageStartupMessages() shh <- suppressPackageStartupMessages try({shh(library(colorout))}, silent=TRUE) ## Source support functions { supportFilesToSource <- grep("\\.[rR]$", dir(supportFnDir, full=TRUE), value=TRUE) message("Sourcing ", length(supportFilesToSource), " files") for(file in supportFilesToSource) source(file) } # cranMir <- "http://lib.stat.cmu.edu/R/CRAN/" cranMir <- c("RSTUDIO" = "http://cran.rstudio.com/") quiet <- TRUE ## FALSE # The number of parallel processes to use for a parallel install of more than one source package. # Values greater than one are supported if the ‘make’ command specified by ‘Sys.getenv("MAKE", "make")’ accepts argument ‘-k -j Ncpus’ Ncpus <- 4 ## Set option for installs options(repos = cranMir) ## SAVE JUST IN CASE save.image() # Try to auto update `pkgsBeingUsed` try(source("~rsaporta/git/misc/rscripts/utilsRS.r"), silent=TRUE) try(source("~rsaporta/git/misc/rscripts/utils/findFnsInFile.R"), silent=TRUE) if (exists("findPkgsInFile")) try({ if (!exists("as.path")) as.path <- function(...) { gsub("/$", "", gsub("/root/git", "~rsaporta/git", paste(..., sep="/"))) } install_if_missing("stringr", attach_after_install=TRUE, verbose=FALSE, update_if_exists=FALSE) foldersToSearch <- c("~/git/", "~/git/misc/rscripts") ## TODO: Just because I have a call to it in some source code ## does not mean it is a valid package. ## eg: Rcurl, microbmenchmark message("Searching for and reading '*.R' files to look for additional packages commonly used") pkgsBeingUsed <- suppressWarnings(findPkgsInFile(foldersToSearch)) ## There is some sloppiness in the findPkgsInFile function -- thus cleanit up pkgsBeingUsed <- pkgsBeingUsed[!grepl("(^[0-9])|\\[|\\]|`", pkgsBeingUsed)] pkgsBeingUsed <- setdiff(pkgsBeingUsed, these_are_not_package_names) ## Append pkgsBeingUsed pkgList <- unique(c(pkgList, pkgsBeingUsed)) }) ## CLEAN UP THE LISTS, NAMING THEM pkgList <- setdiff(pkgList, these_are_not_package_names) pkgList <- setNames(nm=pkgList) GH_vec <- unlist(sapply(names(GitHubInstalls), function(u) sprintf("%s/%s", u, GitHubInstalls[[u]]))) GH_vec <- setNames(nm=GH_vec) ## FIRST INSTALLS: colorout to see the errors -- ## but needs devtools -- ## which needs RCurl ## ## IMPORTANT -- RCurl needs to be (1) installed (2) setup ## Setup for RCurl includes setting up libcurl and curl-config ## ## Thus, try installing from CRAN install_if_missing("RCurl", attach_after_install = TRUE, verbose=FALSE, update_if_exists=FALSE) install_if_missing("devtools", attach_after_install = TRUE, verbose=FALSE, update_if_exists=FALSE) ## COLOROUT if (!("colorout" %in% rownames(installed.packages()))) { if (suppressWarnings(shh(require(devtools, quietly=TRUE, warn=FALSE)))) devtools::install_github("jalvesaq/colorout") else try (install.packages("colorout", type="source", repos=cranMir, quiet=TRUE)) if (!shh(require(colorout))) { message(" --- DEVTOOLS NOT INSTALLED; TRYING MANUALLY COLOROUT ----") try({ dfile <- paste0(getwd(), .Platform$file.sep, "colorout_1.0-1.tar.gz") download.file("http://www.lepem.ufc.br/jaa/colorout_1.0-1.tar.gz", destfile = dfile) install.packages("colorout_1.0-1.tar.gz", type = "source", repos = NULL, quiet=quiet) unlink(dfile) }, silent=TRUE) } } else shh(require(colorout)) ## ------------- THE BIG ONES ------------- ## .safetybreak <- 1 last_results <- Inf results <- 5*length(pkgList)^3 + length(GH_vec) while (sum(results) < sum(last_results) && any(sapply(results, Negate(isTRUE))) && .safetybreak < 25) { ## For iteration purposes cat(" ----------------------- iteration # ", .safetybreak, " -----------------------\n") last_results <- results ## See what remains remaining.cr <- pkgList[ !is.installed(pkgList) ] remaining.gh <- GH_vec [ !is.installed(GH_vec) ] ## Verbose to user cat( sprintf("%-8s: %3i out of %3i installed -- %3i remaining", "CRAN" , length(pkgList)-length(remaining.cr), length(pkgList), length(remaining.cr)) , sprintf("%-8s: %3i out of %3i installed -- %3i remaining", "GitHub", length(GH_vec) -length(remaining.gh), length(GH_vec), length(remaining.gh)) , sep="\n") ## INSTALL MAIN Packages results.cr <- try(sapply(remaining.cr, install_if_missing, update_if_exists=TRUE, quiet=quiet)) results.gh <- try(sapply(remaining.gh, install_if_missing, update_if_exists=TRUE, quiet=quiet)) results <- c(results.cr, results.gh) ## KEEP TRYING UNTIL NO MORE PROGRESS IS MADE ## Some installations might pull in dependencies needed for other installations. .safetybreak <- .safetybreak + 1 } if (.safetybreak <= 2) warning ("Either all installations went perfectly, or the while loop did not iterate. \n The '.safetybreak' is still at ", .safetybreak, ".") if (length(remaining.cr)) message("The following CRAN packages did not install properly:\n ", paste0(remaining.cr, collapse=", ")) if (length(remaining.gh)) message("The following GitHub packages did not install properly:\n ", paste0(remaining.gh, collapse=", ")) ## FONTS ## http://cran.r-project.org/web/packages/extrafont/README.html if (shh(require(extrafont))) { try(loadfonts()) } ## INSTALL RStan if (!shh(require(rstan))) { try(source('http://mc-stan.org/rstan/install.R', echo=TRUE, max.deparse.length=2000)) try(install_rstan()) message(" ----- RSTAN HAS BEEN INSTALLED ----- \n ----- DONT FORGET TO quit() & RESTART R ----- ") } cat(" ----- END OF INSTAL PROCESS -----\n")