Skip to content

Instantly share code, notes, and snippets.

@tallguyjenks
Created August 31, 2020 16:01
Show Gist options
  • Save tallguyjenks/0f17d578df9d8eed2ba31d7a30999a6f to your computer and use it in GitHub Desktop.
Save tallguyjenks/0f17d578df9d8eed2ba31d7a30999a6f to your computer and use it in GitHub Desktop.
Easily Load R Packages programmatically
# 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()
@yihui
Copy link

yihui commented Sep 5, 2020

Or xfun::pkg_attach2(), which does the same thing: https://yihui.org/en/2018/09/xfun-pkg-attach/

xfun::pkg_attach2(c('tidyverse', 'runes', 'patchwork'))

@tallguyjenks
Copy link
Author

@yihui Thats awesome! thank you very much!

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