Skip to content

Instantly share code, notes, and snippets.

@arcaravaggi
Created April 26, 2020 09:08
Show Gist options
  • Save arcaravaggi/029354c3e46d94b999419a3c72215005 to your computer and use it in GitHub Desktop.
Save arcaravaggi/029354c3e46d94b999419a3c72215005 to your computer and use it in GitHub Desktop.
Function to load a list of packages and install package if absent
# Function to load a list of packages
# Installs if package is absent
#
# Pass character vector
# E.g. ipak(c("beepr", "dplyr", "adehabitat"))
#
ipak <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment