Skip to content

Instantly share code, notes, and snippets.

@benjamin-chan
Last active July 1, 2016 20:48
Show Gist options
  • Save benjamin-chan/3b59313e8347fffea425 to your computer and use it in GitHub Desktop.
Save benjamin-chan/3b59313e8347fffea425 to your computer and use it in GitHub Desktop.
R function to install and load packages
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