Adding custom R packages
IBM Software Hub administrators and RStudio users can install custom R packages to use with RStudio.
Users can install the following types of R packages to use in RStudio:
Administrators can install these package types:
- Global R packages
- System R packages
For administrator content, see IBM Software Hub documentation.
User R packages
All RStudio users can install custom R packages to their home folder at /home/wsuser/R/library
. User R packages are not shared with other users or with other projects.
User R packages take precedence over global and system R packages in the runtime image.
R packages that are located in a Storage volume
To install packages located in any user-defined storage volume:
- Create a corresponding Connection asset in the project. For details, refer to Managing assets in projects.
- Restart RStudio if it is running.
- Install the package. For example:
install.packages("zoo", lib="/mnts/YourRpackages")
To load a package located in a user-defined storage volume, use this sample code:
library("zoo", lib.loc="/mnts/YourRpackages")
Shiny apps added to a deployment space can also use packages located in a storage volume. The deployment space must have a valid Connection asset for the storage volume. For details, refer to Deploying Shiny apps from a deployment space.
How to add a custom path to .libPaths
If you have custom packages in a storage volume, you can register their custom destination by using the .libPaths()
command in your applications. This will enable you to load a package by using a plain library
command,
without having to provide the lib.loc
parameter each time.
To register a custom path in your application, use the following template:
.libPaths(c("/home/wsuser/R/library","<your path>",.libPaths()))
- A plain
install.packages()
command writes files to the first path from.libPaths()
by default. - It is recommended that you begin the list of paths in .
libPaths()
with a local directory that gets reset when you start a new RStudio session or Shiny deployment. This makes sure that your applications do not accidentally change packages in a permanent directory. - In user-defined storage volumes, the mount path usually begins with
/mnts
followed by the volume name. To register a custom path for user-defined storage volumes, replace<your path>
with a real path. For example/mnts/YourRpackages
.
Parent topic: RStudio