Difference between revisions of "Rocky R package"

From NIMBioS
 
Line 1: Line 1:
= About =
= About =


The R modules on Rocky have many packages pre-loaded but not all of them.  You are able to install your own packages locally in your home directory.
The R modules on Rocky have many packages pre-loaded but not all of them.  We are able to install our own packages locally in our home directory.




= Installing =
= Installing =


First we load the R module we want to use.  For our example, we're going to use the R/4.2.2-foss-2022b module/version.
First we load the R module we want to use.  For our example, we're going to use R/4.2.2-foss-2022b.


<pre>
<pre>
Line 13: Line 13:




Next we decide on a location for the R packages to be installed, make that directory, and then set the R_LIBS_USER environment variable to point to the new location.  Here I have decided to use the name of the module/version as the directory name.  If I choose to use a different R module/version later, I can choose a different package directory to use.
Next we decide on a location for the R packages to be installed, make that directory, and then set the R_LIBS_USER environment variable to point to the new location.  Here we use the name of the module as the package directory name since each version will need it's own packages installed separately.  


<pre>
<pre>
Line 21: Line 21:




Now I can start R and install the package.  If you have not set a mirror, it will ask you to choose one.
Now we start R and install the package.  If we have not set a mirror, it will ask for us to choose one.
<pre>
<pre>
R
R
Line 30: Line 30:
= Using =
= Using =


In our batch file for our job, we need to load the correct module for R and set the R_LIBS_USER environment variable so that it can find our installed packages.
In our batch file for our job, we load the R module and set the R_LIBS_USER environment variable so that our job can find our installed packages.




Line 47: Line 47:




You will run the job now just like any other job by using the sbatch command.
We run the job just like any other Rocky job by using the sbatch command.


<pre>
<pre>
sbatch spatial_test.sh
sbatch spatial_test.sh
</pre>
</pre>

Latest revision as of 14:07, 29 February 2024

About

The R modules on Rocky have many packages pre-loaded but not all of them. We are able to install our own packages locally in our home directory.


Installing

First we load the R module we want to use. For our example, we're going to use R/4.2.2-foss-2022b.

module load R/4.2.2-foss-2022b


Next we decide on a location for the R packages to be installed, make that directory, and then set the R_LIBS_USER environment variable to point to the new location. Here we use the name of the module as the package directory name since each version will need it's own packages installed separately.

mkdir -p ~/R/4.2.2-foss-2022b
export R_LIBS_USER="$HOME/R/4.2.2-foss-2022b"


Now we start R and install the package. If we have not set a mirror, it will ask for us to choose one.

R
install.packages('adespatial')


Using

In our batch file for our job, we load the R module and set the R_LIBS_USER environment variable so that our job can find our installed packages.


spatial_test.sh

#!/bin/bash

#SBATCH --job-name=SPATIAL_TEST
#SBATCH --output=R_spatial_%j.out

module load R/4.2.2-foss-2022b
export R_LIBS_USER="$HOME/R/4.2.2-foss-2022b"

Rscript spatial.R


We run the job just like any other Rocky job by using the sbatch command.

sbatch spatial_test.sh