Load Multiple Packages at Once in R (Example)
In this tutorial, I’ll illustrate how to load several add-on packages with one line of code in the R programming language.
The article consists of these content blocks:
- Creation of Example Data
- Example: Load Multiple Packages at Once in R
- Video, Further Resources & Summary
Let’s dive right in.
Creation of Example Data
As a first step, we need to specify a vector of package names:
my_packages <- c("dplyr", "mice", "stringr") # Create vector of packages
We have stored the names of three packages in the character vector my_packages. In the next step, I’ll show how to load all of these packages at once…
Example: Load Multiple Packages at Once in R
If we want to load multiple packages at once to R, we can use a combination of the lapply() and require() functions:
lapply(my_packages, require, character.only = TRUE) # Load multiple packages
After running the previous R code, all packages in the vector my_packages are loaded to R.
Video, Further Resources & Summary
I have recently released a video on my YouTube channel, which shows the topics of this article. You can find the video below.
Furthermore, you may want to read the other posts of this homepage:
- Check if Package is Missing and Install Automatically
- Unload Package without Restarting R
- Introduction to the pacman Package in R
- Useful R Packages
- The R Programming Language
Summary: In this article you learned how to load a list of packages to RStudio. Please let me know in the comments below, in case you have further questions.