How to install R packages in different locations?#

The default location for R packages is not writable and you can not install new packages. On demand we install new packages system-wide and for all users. However, it possible to install packages in different locations than root and here are the steps:

  1. create a directory in $HOME e.g. ~/R/libs

  2. create a .profile file

  3. echo 'export R_LIBS_USER=~/R/libs' >> ~/.profile

You need to restart your jupyter server to activate the changes.

Test#

You can check if the new libs Path is loaded:

.libPaths()

The ouput should contain the new path: ~/R/libs

Note

We can also install new packages system-wide for all users. Therefore, we need a link to the package.