Load multiple packages at once

Several permutations of your proposed functions do work -- but only if you specify the character.only argument to be TRUE. Quick example:

lapply(x, require, character.only = TRUE)

This should do the trick:

lapply(x, FUN = function(X) {
    do.call("require", list(X)) 
})

(The key bit is that the args argument in do.call(what, args) must be a list --- even if it only has a single element!)


The CRAN package pacman that I maintain (authored with Dason Kurkiewicz) can accomplish this:

So the user could do:

## install.packages("pacman")
pacman::p_load(dplyr, psych, tm) 

and if the package is missing p_load will download it from CRAN or Bioconductor.

Tags:

R

Packages