0 votes
1 view
in R Programming by (5.1k points)

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 (25.3k points)

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.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...