Get & Set Directory Path of Installed Packages Using libPaths Function in R (3 Examples)

 

This tutorial shows how to get and set the directory path of libraries in R programming.

The tutorial consists of the following content blocks:

Here’s the step-by-step process…

 

Example 1: Getting Path of Directory where R Packages are Stored

In this example, I’ll explain how to identify the directory path where your R packages are installed.

For this, we can use the libPaths function as shown below:

.libPaths()                                        # Get path using .libPaths function
"C:/Program Files/Microsoft/R Open/R-3.5.3/library"

After running the previous R syntax, the RStudio console returns a character string containing our directory of R libraries.

 

Example 2: Setting Path of Directory where R Packages are Stored

Example 2 explains how to change the directory where R add-on packages are saved.

Again, we are using the libPaths function. However, this time we are specifying the new working directory as character string within the function:

.libPaths("C:/Users/Joach/Desktop/my packages")    # Set path using .libPaths function

 

Example 3: Installing Packages to New Directory

Let’s test if the switch of our library directory worked. For instance, we could install the dplyr package to check whether it is stored in our previously specified directory (see Example 2):

install.packages("dplyr")                          # Install dplyr

Have a look at the folder on your computer that you have specified in Example 2. It should contain several R add-on packages.

 

Video & Further Resources

Would you like to learn more about packages in R? Then you may watch the following video of my YouTube channel. I’m explaining the R programming code of this tutorial in the video:

 

The YouTube video will be added soon.

 

Additionally, you may want to read some of the other tutorials on my website:

 

At this point you should know how to find and define the library path in R programming. If you have any further questions, don’t hesitate to tell me about it in the comments.

 

Subscribe to my free statistics 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.

Menu
Top