R and Rstudio Server

R is a programming language and software environment for statistical computing and graphics.  
R offers a wide variety of statistics-related libraries and provides a favorable environment for statistical computing and design. In addition, the R programming language gets used by many quantitative analysts as a programming tool since it's useful for data importing and cleaning.

In order to see different versions of R installed on the cluster, run the command:

module avail R

You can obtain R in your environment by loading the R module i.e.:

module load R

The command R --version returns the version of R you have loaded:

R --version

In order to run the loaded R module you can enter this command to work with it and get the prompt:

R

To check available libraries and packages inside R, use the following command:

library(library-name)
OR
installed.packages()

For adding a new package that is missing you can install it using the command:

install.packages("package-name")

RStudio Server 
Rstudio server enables you to provide a browser-based interface to a version of R running on a remote Linux server, bringing the power and productivity of the RStudio IDE to server-based deployments of R.
Users can see the installed Rstudio versions by running the following commands:

module avail rstudio-server

The command output will list down all the installed versions of the module. Follow these instructions to load Rstudio:-

RStudio Server is not allowed on the head node; it must be run in an interactive Slurm
session. 

srun --partition=<name of partition> --time=<hours:minutes:seconds> --cpus-per-task=<# of cpus> --mem=<amount of memory to use> --pty 

For example:

$srun --partition=high2 --time=9:00:00 --cpus-per-task=4 --mem=20G --pty /bin/bash -l

Once your session launches, load the R module, the R studio server module, and then launch rstudio.

$module load R
$module load rstudio-server

Launch studio server.

$rstudio-launch

Please note the instructions displayed in the terminal. You will need these to connect. These will be tailored to your account and remote Slurm instance:

You need to use SSH tunneling to allow your computer to communicate with
RStudio Server on the cluster.

Run the following command in a new terminal on your computer:

   ssh -L40432:cpu-6-91:40432 mkeenan@farm.hpc.ucdavis.edu

Then, on your computer, navigate your browser to:

   URL: http://localhost:40432
   Username: mkeenan
   Password: correct-horse-battery-staple