# Using system R with user installed packages In my previous posts [here](/posts/installing-user-r-version-on-infrastructure) and [here](/posts/updating-r-libraries-after-r-version-update), I showed you how to maintain your own R install, and update the libraries after you update your own R version. Today, I'm going to cover an easier topic, how to use the system R installs. We have a variety of versions of R on the infrastructure. By default, you are most likely to use the system version of R that comes with CentOS 7, which is found in `/usr/bin/R` and `/bin/R`, which happens to be 3.3.1 and is from 2016. Let's take a look at what's available that we have installed for you: ``` # davised:Linux @ waterman in ~ [22:32:26] $ ls -1d /local/cluster/R-* /local/cluster/R-3.2.5 /local/cluster/R-3.3.1 /local/cluster/R-3.3.1.c7 /local/cluster/R-3.3.2 /local/cluster/R-3.4.1 /local/cluster/R-3.4.2 /local/cluster/R-3.5.0 /local/cluster/R-3.5.1 /local/cluster/R-3.6.0 /local/cluster/R-3.6.1 /local/cluster/R-4.0.2 ``` To get the latest version of R accessible to you, we'll need to edit your `.cshrc` or `.bashrc` depending on which shell you are using. Here are the commands to do so: ``` echo 'export PATH=/local/cluster/R-4.0.2/bin:${PATH}' >> ~/.bashrc echo 'setenv PATH /local/cluster/R-4.0.2/bin:${PATH}' >> ~/.cshrc ``` You can log out and log back in, or `source` the appropriate file to make sure the changes have taken place: ``` $ R --version R version 4.0.2 (2020-06-22) -- "Taking Off Again" Copyright (C) 2020 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under the terms of the GNU General Public License versions 2 or 3. For more information about these matters see https://www.gnu.org/licenses/. ``` You can maintain your packages in your lab space the same way as I previously covered in the [first post](/posts/installing-user-r-version-on-infrastructure). You might simplify the path a bit, and you can decide if you want to maintain a record of packages for each R install, e.g. ``` mkdir -p /nfs3/CGRB/home/davised/opt/R/library/4.0.2 export R_LIBS=/nfs3/CGRB/home/davised/opt/R/library/4.0.2 #bash setenv R_LIBS /nfs3/CGRB/home/davised/opt/R/library/4.0.2 #tcsh ``` Then, you can iterate directories when new verisons come out, e.g. if 4.0.3 is the next version: ``` mkdir -p /nfs3/CGRB/home/davised/opt/R/library/4.0.3 export R_LIBS=/nfs3/CGRB/home/davised/opt/R/library/4.0.3 #bash setenv R_LIBS /nfs3/CGRB/home/davised/opt/R/library/4.0.3 #tcsh ``` OR, for a more simple library variable: ``` mkdir -p /nfs3/CGRB/home/davised/opt/R/library export R_LIBS=/nfs3/CGRB/home/davised/opt/R/library #bash setenv R_LIBS /nfs3/CGRB/home/davised/opt/R/library #tcsh ``` You need to add the export or setenv commands, for bash and tcsh into your .bashrc or .cshrc files, respectively, for the commands to remain after login/logout. Load up an R session and test out the new `$R_LIBS` environment variable that you set: ``` > install.packages("remotes", repos="https://ftp.osuosl.org/pub/cran") Installing package into ‘/nfs3/CGRB/home/davised/opt/R/library’ (as ‘lib’ is unspecified) ``` You'll see that I went with the second option. I generally copy a backup of the library dir to a backup folder on big version jumps, just in case some error really slows down my work, I have something to fall back to. But, otherwise, having a single folder for R libraries has not caused me too much trouble. Whatever way you maintain your R, be it through the `/local/cluster/R-` versions or your own, you should be covered. Feel free to request R version upgrades if we don't get to them soon enough using the relatively new [cgrb-software request form](http://shell.cgrb.oregonstate.edu/support/). Help us out by choosing cgrb-software from the dropdown menu. Thanks, and good luck!