Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in R Programming by (7.3k points)
edited by

How can I load a bunch of packages at once without 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)

1 Answer

0 votes
by
edited by

To load multiple packages in R, use the following:

packages <- c("randomForest","lubridate","ggplot2", "dplyr")

lapply(packages, library, character.only = TRUE)

library() or require() load only one package at a time. Using the above code will load multiple packages.

NOTE: Ensure that the packages are installed in the R environment before you load them.

Browse Categories

...