Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

library() function fails to load multiple packages

Tags:

r

When I included janitor package with other packages, it did not load.

library(MASS, caret, stepPlr, janitor)

Error in library(MASS, caret, stepPlr, janitor) : object 'janitor' not found

When I ran that command separately with only janitor package, it got loaded into session; with no error

> library(janitor)
Warning message:
package ‘janitor’ was built under R version 3.3.3 

Is there any limit with including x number of packages at a time? Or there is something wrong with my RStudio?

like image 782
Wwalk Avatar asked Dec 12 '25 14:12

Wwalk


1 Answers

The function p_load from the pacman package allows for listing multiple packages like this, and will install them if any are not already present:

library(pacman)
p_load(MASS, caret, stepPlr, janitor)

This is not only user-friendly, it also improves reproducibility for running the same script across multiple users or environments.

like image 139
Sam Firke Avatar answered Dec 14 '25 03:12

Sam Firke