How to permanently set the library installation path?
You can change the path in which your R libraries are installed. You could do this because you only have a very limited amount of space in your home directory, and R packages easily eat up your available space until eventually, you receive strange error messages and programs stop to work because you are out of space.
- Create a file called .Rprofile in your home directory (that is, after you log in to schroedinger or spinoza, for example).
- Add the following R code to this file and save: .libPaths("/g/[groupshare]/[username]/R"). Adjust the path accordingly. For example, I decided to store all manually installed R libraries in a folder called R within our group directory and NOT in the home directory.
- Important: Restart your R session. Log out of your session, you may even have to create a new project or so because it may happen that the session is not properly reset otherwise. Verify that everything worked by typing: .libPaths(). You should now see your personal path at the beginning of the list, followed by other paths (possibly). The important point is that your personal path is the first element in the vector. If not, your change was not recognized, please let me know.
- Delete all files and folders in the R directory that is located in your home to free up space (rm -r ~/R). You may have to reinstall some manually installed packages, but at least you have a clean and fresh install then. Remember that a lot of packages are already available on the servers, so you often do not even have to do this.
How to set RStudio environment variables for each session?
Create a file called ~/.Renviron. For example to set the path where local libraries are installed:
echo "R_LIBS_USER=/home/<user>/myR/library” > ~/.Renviron
How to set other RStudio settings for each session?
Instead of creating a ~/.Renviron file you can also create a ~/.Rprofile file in which you can just use R. So changing the user library path can also be set like so: