R¶
R is a free software environment for statistical computing and graphics.
Using R in a Jupyter notebook¶
Through ondemand.boisestate.edu you can access a Jupyter notebook running on Borah. (More info about OnDemand.) Jupyter notebooks can be used to run R, but first you'll need to create a conda environment and install the R-kernel.
-
Before we can do any of the next steps, we'll need to install a conda/mamba distribution. We recommend miniforge: Installing miniforge.
Info
You may want to run the next steps in an interactive session, so your process is not killed on the login node. Use
dev-sessionto request an interactive session. -
Once mamba/conda is installed, we'll use it to create a new environment:
In this example, we're creating an environment calledmamba create -n r-env -c conda-forge r-recommended r-irkernel jupyterr-envand pulling the packagesr-recommended,r-irkernel, andjupyterfrom theconda-forgechannel.Info
If you installed a different conda/mamba distribution (e.g., miniconda), you may need to replace
mambawithconda. -
After the environment is created, we'll activate it and install the interactive R kernel:
mamba activate r-env R -e 'IRkernel::installspec()'
And that concludes the installation! To use the newly-installed R-kernel, navigate to ondemand.boisestate.edu and request a Jupyter Notebook session through the Interactive Apps tab. On the notebook screen, open the dropdown for a "New" notebook and select "R".
Installing R packages¶
There are many R packages beyond the standard library.
If you find yourself getting an error like there is no package called
‘PACKAGENAME’, you probably need to install a package.
Here are a couple ways you can install packages in R:
Using Conda/Mamba¶
Many R packages are hosted on the conda-forge channel using the naming
convention r-PACKAGENAME where PACKAGENAME is the name of the R package,
e.g., r-tidyverse.
If you want to check if an R package is available via conda or check what
builds/versions are available, try searching r-PACKAGENAME with the name of
the package you're looking for) on
anaconda.org.
-
To install an R package into an existing environment:
mamba activate r-env mamba install -c conda-forge r-PACKAGENAME(See above for how to install R in a conda environment.)
-
To create a new environment containing your R package:
mamba create -n r-env -c conda-forge r-recommended r-PACKAGENAME
For both methods, you'll need to activate the environment each time before calling R:
mamba activate r-env
Using a module¶
-
Load an R module:
module load borah-misc r/4.2.2 -
Start an R terminal and install your desired package:
Rinstall.packages("PACKAGENAME")where
PACKAGENAMEis the name of the package you want to install. It will ask if you want to install into a personal library in your home directory—say yes—and ask you to select a mirror—you can just choose the geographically closest one.
Once the package is finished installing, you're ready to go. If you run into issues installing a package, please contact researchcomputing@boisestate.edu.
Submitting an R job to the scheduler¶
Once you have your R packages installed you're ready to submit a job to the scheduler. (More info about scheduling a job.)
Below is an example submission script if you are using R from a module:
| r-slurm.sh | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
This script can be submitted using sbatch:
sbatch r-slurm.sh
If you are using R from a conda environment, just replace lines 9 and 10 in the above script (highlighted) with the following:
| r-slurm.sh | |
|---|---|
9 10 11 | |