Skip to content

Instantly share code, notes, and snippets.

@achateigner
Forked from stevenworthington/ipak.R
Last active August 29, 2017 12:22
Show Gist options
  • Save achateigner/f7948d43f34c1d1bcd83097036338601 to your computer and use it in GitHub Desktop.
Save achateigner/f7948d43f34c1d1bcd83097036338601 to your computer and use it in GitHub Desktop.
Install and load multiple R packages at once
ipak <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE)
# if install fails, try bioconductor
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg)){
if (! any(grep("BiocInstaller", search()))){
source("https://bioconductor.org/biocLite.R")
library(BiocInstaller)
}
biocLite(new.pkg, ask=F)
}
sapply(pkg, require, character.only = TRUE)
}
# to load:
# install.packages("devtools")
# library(devtools)
# source_url("https://gist.github.com/achateigner/f7948d43f34c1d1bcd83097036338601/raw/ipak.R")
@achateigner
Copy link
Author

I forked the stevenworthington's ipak, and added the automatic installation from bioconductor when a package is not found on CRAN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment