-
-
Save RobertMyles/96665be044540e9ac668ee697dac6db7 to your computer and use it in GitHub Desktop.
# library() or require() only load one package at a time | |
# but... | |
Packages <- c("dplyr", "ggplot2", "rstan", "readr") | |
lapply(Packages, library, character.only = TRUE) | |
# this loads as many as you put in 'Packages'. They need to be installed first, of course. |
Nice. Wrapping it in invisible()
is also convenient :)
perfect!
Awesome, thank you!
If one is too lazy to ""
.
load_pkg <- rlang::quos(tidyverse, tidylog, lubridate, readxl, janitor, tictoc)
invisible(lapply(lapply(load_pkg, rlang::quo_name),
library,
character.only = TRUE
))
@leungi Haha, laziness is always good!
Actually, I use Yihui's xfun package for this now. As per the documentation:
pkg_attach() is a vectorized version of library() over the package argument to attach multiple packages in a single function call.
xfun::pkg_attach(<pkgs>)
Where <pkgs>
is character vector of package names. Super lazy :-)
Thanks for tip @RobertMyles 👍
I usually use pacman::p_load()
, but just realized during RStudio Connect deployment, it'll attempt to re-install every packages, regardless if it's installed or not!
I checked xfun::pkg_attach()
, and it seems it has a check xfun::loadable()
, which should avoid the above.
Thanks for the share! much convenient than pacman::
Thanks. It works for me. Simple and easy