Created
April 26, 2020 09:08
-
-
Save arcaravaggi/029354c3e46d94b999419a3c72215005 to your computer and use it in GitHub Desktop.
Function to load a list of packages and install package if absent
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
# 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