-
-
Save achateigner/f7948d43f34c1d1bcd83097036338601 to your computer and use it in GitHub Desktop.
Install and load multiple R packages at once
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I forked the stevenworthington's ipak, and added the automatic installation from bioconductor when a package is not found on CRAN.