Skip to content

Instantly share code, notes, and snippets.

@arnauldvm
Last active March 13, 2019 15:37
Show Gist options
  • Save arnauldvm/99dd4c8eb785016bff56d9c98fa273ae to your computer and use it in GitHub Desktop.
Save arnauldvm/99dd4c8eb785016bff56d9c98fa273ae to your computer and use it in GitHub Desktop.
R library auto install
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