13 Installing the Package

In this chapter, we’ll cover how to install your package and explain the difference between installing it and using the “Load All” feature in RStudio.

Once you have developed your package and are ready to use it or share it with others, you’ll need to install it. RStudio provides a convenient way to install your package using the “Install and Restart” button.

13.1 “Install and Restart” Button

  1. In RStudio, go to the “Build” tab.
  2. Click on the “Install and Restart” button.

This will compile your package, including all functions, data, and documentation, and install it into your R library. Finally, this will also load your newly installed package using the library function:



13.2 From a Local Directory

Alternatively, you can install your package from a local directory using the devtools package. Here’s how you can do it:

devtools::install_local("path/to/your/package")

Replace “path/to/your/package” with the actual path to your package directory.



13.2.1 Troubleshooting Tips

Note! If you encounter error messages such as “Error Retrieving Help” […] and/or “…myPackage.rdb’ is corrupt’”, restart your RStudio session, and the issue should be resolved. See the videos below for more information:




13.3 Installing from GitHub

If your package is hosted on GitHub, you can install it directly from GitHub using:

devtools::install_github("yourusername/yourrepository")

Replace “yourusername/yourrepository” with your actual GitHub username and repository name.


13.4 Installing vs. “Load All”

13.4.1 Installing the Package

When you install a package using the “Install and Restart” button or the install function, R compiles the package and its documentation, and places it in the library directory where other installed packages are located. Once installed, you can load the package using the library function, and it becomes available for use in any R session.

13.4.2 Using “Load All”

The “Load All” feature in RStudio, accessible via the devtools::load_all() function or through the “Build” tab by selecting “More” and then “Load All,” is a convenient way to load all functions and data from your package into the R environment without formally installing it. This is particularly useful during development because it allows you to test and debug your package quickly without going through the installation process.

However, “Load All” is specific to your current working environment and does not compile the package or its documentation. Therefore, it is not a substitute for installing the package when you are ready to distribute it or use it in a different environment.


In the next chapter, we’ll delve into creating vignettes.




Creating R Packages: A Step-by-Step Guide by Ville Langén is licensed under CC BY-SA 4.0