Created
April 1, 2017 16:58
-
-
Save wesleyit/75d6c2c25dabef1e131661b57db2dc5b to your computer and use it in GitHub Desktop.
This snippet will load the libraries in a smarter way. If the library is already installed, then it is loaded. Otherwise, it is installed and then loaded.
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
ensure_pkg <- function(pkg) { | |
pkg = toString(substitute(pkg)) | |
if (!require(pkg, character.only = TRUE)){ | |
install.packages(pkg) | |
require(pkg) | |
} | |
} | |
ensure_pkg("car") | |
ensure_pkg("lattice") | |
ensure_pkg("rpart") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment