Last active
July 1, 2016 20:48
-
-
Save benjamin-chan/3b59313e8347fffea425 to your computer and use it in GitHub Desktop.
R function to install and load packages
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
loadPkg <- function (pkg) { | |
# pkg should be an as.character() object | |
repos <- "http://cloud.r-project.org" | |
if (!require(pkg, character.only=TRUE)) { | |
install.packages(pkg, dependencies=TRUE, repos=repos) | |
} | |
require(pkg, character.only=TRUE) | |
} | |
# loadPkg("data.table") | |
# loadPkg("xtable") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment