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:

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:

 

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.

 

Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.


Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Top