Created
September 13, 2017 10:36
-
-
Save keuv-grvl/b685d8c0ed7525c521cf7064767515c5 to your computer and use it in GitHub Desktop.
Install a R package if not already installed, then load it
This file contains hidden or 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
loadOrInstall <- function(pkgname, CRANmirror.index=1) { | |
chooseCRANmirror(ind=CRANmirror.index) | |
if (! pkgname %in% installed.packages()[,1]) { | |
write("installing", stderr()) | |
install.packages(pkgname, dep=T) | |
} else { write("already installed", stderr()) } | |
library(pkgname, character.only = TRUE) | |
write("loaded",stderr()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment