We do not ship R with the SCC as every use case demands a different set of packages and versions. This means, that you need to install R yourself. This also includes any R package as well as RStudio.
This page is going to show how to install R and the packages in project specific "environments". We are also going to show how to conveniently use R by using either RStudio or Visual Studio Code.
Attention
Installing R packages works differently using the approach presented here.
Instead of using the CRAN repository you should install R packages using pixi
from
the anaconda repositories. This avoids lot of compilation and compatibility issues.
What is a (conda) environment?
An environment is basically a folder in which software gets installed by a package manager. The package manager also takes care of installing all the packages and libraries that are needed by the software (so-called dependencies).
The great thing about these environments is that they are isolated from each other. This means that you can have one for project A and another one for project B and they are not going to interfere with each other.
There are multiple package managers to create and manage environments. This guide is going to use pixi
but it can basically be
done with any anaconda type package manager.
Install pixi
To install pixi, all you need to do is open a terminal and enter:
curl -fsSL https://pixi.sh/install.sh | bash
cp /etc/skel/.bash_profile ~/
Accept all default options. When it is done, you need to restart your terminal.
Now you should get some output when you enter pixi
in the terminal.
Prepare an environment
Create some folder where your project is going to live, enter it and issue pixi init
:
mkdir my_project
cd my_project
pixi init
This creates a pixi.toml
file which contains all the configuration. One important
thing to do is to add the following lines to the pixi.toml
file:
[system-requirements]
linux = "4.18"
Now you can use pixi add
to install the packages you need. For instance, to install
the R interpreter and the lme4
package, you would do:
pixi add r-base r-lme4
If you need other packages, search for them on https://anaconda.org. For instance, to install the ggplot2
package, you would do:
pixi add r-ggplot2
Using your environment
To use your environment, you need to enter it. This is done by issuing:
pixi shell
Now you can start R by entering R
in the terminal.
RStudio
RStudio cannot be installed in an environment using pixi
. Instead, you need to install it in you home folder.
First, you need to download it.
Head over to https://posit.co/download/rstudio-desktop/. Make sure to scroll
down and choose the "Zip/Tarball" version. Choose the "Fedora 34/Red Hat 8" one.
If you use an interactive session, you can do this in the web browser running inside the session.
You are going to end up with a .tar.gz
file that starts with rstudio
.
I advise you to create a bin
folder in your home folder where you are going to
put all your custom installed software. Then install RStudio there:
cd
mkdir bin
cd bin
tar -xzf ~/Downloads/rstudio-1.4.1717-fedora-x86_64.tar.gz
Be aware that the filename you downloaded might be different.
Now, go back to the folder of the project, make sure you are in the pixi environment and start RStudio:
cd
cd my_project
pixi shell
~/bin/rstudio-1.4.1717/rstudio
Also be advised that the folder name might be different, depending on the version you downloaded.
Visual Studio Code
Another convenient way to use R is by using Visual Studio Code. This is especially convenient on the SCC Pilot because you can have an interactive tunnel session through which you can connect your locally running Visual Studio Code to the cluster. In order to do this, first download and install Visual Studio Code on your local machine.
Attention
You do not need to install Visual Studio Code on the cluster!
Just install it on your local machine.
Now, install the "Remote - SSH" extension in Visual Studio Code. If you have not done this yet, prepare your computer as well as the cluster for an interactive tunnel session using these instructions.
Once you have connected your Visual Studio Code to the cluster, you need to install the R
extension. Additionally,
you also need a few extra packages in your environment:
pixi add r-languageserver r-httpgd radian
Last but not least, you need to alter some settings so the R
extension can find the R
interpreter. You can set these
for all projects or just the current one.
Open the settings by pressing Ctrl + Shift + p
and search for "Preference: Open User Settings (JSON)" if you want to change it
for all projects or "Preference: Open Workspace Settings (JSON)" if you want to change it for the current project only.
A settings.json
is going to open. You need to add the following lines before the last curly brace:
"r.rpath.linux": "${workspaceFolder}/.pixi/envs/default/bin/R",
"r.alwaysUseActiveTerminal": true,
"r.plot.useHttpgd": true,
"r.rpath.mac": "${workspaceFolder}/.pixi/envs/default/bin/R",
"r.rterm.linux": "${workspaceFolder}/.pixi/envs/default/bin/radian",
"r.rterm.mac": "${workspaceFolder}/.pixi/envs/default/bin/R",
"r.rterm.option": ["--r-binary=${workspaceFolder}/.pixi/envs/default/bin/R"],
When you are done, you can start R by pressing Ctrl + Shift + p
and searching for "R: Create R Terminal".
Now you can run your R files in this terminal from the editor pane.