Skip to content

Instantly share code, notes, and snippets.

@IdoBar
Last active July 31, 2016 22:16
Show Gist options
  • Save IdoBar/1c56a5a9f6836b93dd9a458957fb03c8 to your computer and use it in GitHub Desktop.
Save IdoBar/1c56a5a9f6836b93dd9a458957fb03c8 to your computer and use it in GitHub Desktop.
Install dependencies in R
# Load GO and DE data to R
## @knitr prep_data
# Install missing CRAN packages if needed
# git.packages <- c("docopt/docopt.R")
# github.packages <- c("argparser")
install.deps <- function(p, repo="cran"){
call_install <- switch(repo,cran=c("install.packages(package, repos=\"http://cloud.r-project.org/\""),
bioc=c("biocLite(package, suppressUpdates=TRUE"),
git=c("install.github(package"))
if (repo=="bioc") eval(parse(text = getURL("http://bioconductor.org/biocLite.R", ssl.verifypeer=FALSE)))
for (package in p) {
if (!package %in% installed.packages()) {
cat(sprintf("Please wait, installing and loading missing package %s and its dependencies from %s.\n",
package, repo), file=stderr())
suppressWarnings(eval(parse(text = sprintf("%s, quiet = TRUE)",call_install))))
if (!package %in% installed.packages()) {
ifelse(!interactive(),q("no", 2, TRUE),
stop(sprintf("Unable to install missing package %s from %s.\n",
package, repo), call. = FALSE))
}
}
require(package, character.only=TRUE, quietly=TRUE, warn.conflicts=TRUE)
}
}
# Install and load cran packages
CRAN_packages <- c("RCurl", "pander", "grid", "RColorBrewer", "dplyr", "ggplot2", "knitr")
install.deps(CRAN_packages)
# Install and load bioconductor packages
bioc_packages <- c("qvalue","goseq", "GO.db")
install.deps(bioc_packages, repo="bioc")
# Reload dplyr (must be last package loaded)
detach("package:dplyr", unload=TRUE)
library(dplyr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment