Skip to content

Instantly share code, notes, and snippets.

@pachadotdev
Created October 12, 2016 18:05
Show Gist options
  • Save pachadotdev/a761a35602a2386024e304c5d034c4b9 to your computer and use it in GitHub Desktop.
Save pachadotdev/a761a35602a2386024e304c5d034c4b9 to your computer and use it in GitHub Desktop.
Automatically downloads and/or load the libraries for your Rmds/R scripts
download_and_or_load <- function(x){
y <- x[!(x %in% installed.packages()[, "Package"])]
if (length(y))
install.packages(y, dependencies = TRUE)
sapply(x, require, character.only = TRUE)
}
my_libraries <- c("ggplot2", "dplyr", "purrr")
download_and_or_load(my_libraries)
@pachadotdev
Copy link
Author

Tired of R code not working on the fly even between your own computers? Think in a reproducible way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment