-
-
Save danieltomasz/1db8c0d6404b0793114eca38210f23a8 to your computer and use it in GitHub Desktop.
Check if multiple R packages are installed. Install them if they are not,then load them into the R session.
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
# check.packages function: install and load multiple R packages. | |
# Check to see if packages are installed. Install them if they are not, then load them into the R session. | |
check.packages <- function(pkg){ | |
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])] | |
if (length(new.pkg)) | |
install.packages(new.pkg, dependencies = TRUE) | |
sapply(pkg, require, character.only = TRUE) | |
} | |
# Usage example | |
packages<-c("ggplot2", "afex", "ez", "Hmisc", "pander", "plyr") | |
check.packages(packages) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment