Last active
March 13, 2019 15:37
-
-
Save arnauldvm/99dd4c8eb785016bff56d9c98fa273ae to your computer and use it in GitHub Desktop.
R library auto install
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
load_lib = function(lib_name) { | |
if (!require(package=lib_name, character.only=TRUE)) { | |
install.packages(lib_name) | |
if (!require(package=lib_name, character.only=TRUE)) stop(paste0("Package '", lib_name, "' not found")) | |
} | |
library(package=lib_name, character.only=TRUE) | |
} | |
# Usage: | |
load_lib("data.table") # for example |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment