Skip to content

Instantly share code, notes, and snippets.

@chrisvoncsefalvay
Created August 11, 2018 11:30
Show Gist options
  • Save chrisvoncsefalvay/08b3dcb424d8f5ebae7f5cbaf9b5d2ac to your computer and use it in GitHub Desktop.
Save chrisvoncsefalvay/08b3dcb424d8f5ebae7f5cbaf9b5d2ac to your computer and use it in GitHub Desktop.
Install if not present
# R code that checks if a package is installed, and installs it from CRAN if not.
#' Install packages from a list if not present
#'
#' Installs packages from a provided list if they are not already installed.
#'
#' @param packages_list a list of packages to be installed
#'
#' @export
cran_install_if_not_present <- function(packages_list) {
tbi <- packages_list[!(packages_list %in% installed.packages()[,"Package"])]
if(length(tbi)) {
install.packages(tbi)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment