2

I'd like to use pacman's p_load function. I've read through the documentation and understand how to pass multiple packages into the function directly. However, I'd like to store the package names separately and feed them into pacman so that I can use this same 'list' to later test that the packages have been loaded into the environment.

Based on the documentation, pacman is expecting a character vector. my first attempt was:

pkg_list <- as.vector(c("tidyverse", "forecast")

or

pkg_list <- "tidyverse, forecast"

followed by:

pacman::p_load(pkg_list)

or

pacman::p_load(pkg_list, character.only = FALSE)

Which all return the same error stating:

package ‘pkg_list’ is not available

Fine, it's obviously looking for a package called pkg_list instead of the contents of the object so I also tried using a list and unlisting it in the p_load statement, using eval, etc. but p_load always seems to evaluate whatever is input as a literal.

Just trying to better understand why and how to escape that literal evaluation if possible.

  • 5
    It should have been `character.only=TRUE`. Try `pkg_list <-c("tidyverse", "forecast"); pacman::p_load(pkg_list, character.only = TRUE)` – MrFlick Feb 13 '19 at 21:31
  • Ah, for some reason I had it in my head that character.only = TRUE was the default. You're absolutely right, that works. Thanks! – semisolidwhale Feb 13 '19 at 21:37
  • BTW: in this context, `as.vector(c("tidyverse", "forecast"))` (you forgot the last paren) is the same as `c("tidyverse", "forecast")`, which is already a vector. – r2evans Feb 13 '19 at 22:13

0 Answers0