Created
August 31, 2020 16:01
-
-
Save tallguyjenks/0f17d578df9d8eed2ba31d7a30999a6f to your computer and use it in GitHub Desktop.
Easily Load R Packages programmatically
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
# Package names | |
packages <- c('tidyverse', 'runes', 'patchwork') | |
# Install packages not yet installed | |
installed_packages <- packages %in% rownames(installed.packages()) | |
if (any(installed_packages == FALSE)) { | |
install.packages(packages[!installed_packages]) | |
} | |
# Packages loading | |
lapply(packages, library, character.only = TRUE) %>% | |
invisible() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or
xfun::pkg_attach2()
, which does the same thing: https://yihui.org/en/2018/09/xfun-pkg-attach/