Load multiple packages at once

Tyler Rinker picture Tyler Rinker · Nov 18, 2011 · Viewed 88.5k times · Source

How can I load a bunch of packages at once with out retyping the require command over and over? I've tried three approaches all of which crash and burn.

Basically, I want to supply a vector of package names to a function that will load them.

x<-c("plyr", "psych", "tm")

require(x)
lapply(x, require)
do.call("require", x)

Answer

daroczig picture daroczig · Nov 18, 2011

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)