Running R in a Jupyter Notebook on TACC Vista
Vista has no R module. module spider R returns fuzzy matches (amber, arpack, paraview) and nothing else, so R has to be installed per-user through conda. This guide sets up a single Jupyter kernel that runs Python and R in the same notebook via rpy2.
Everything below assumes Vista specifically: ARM64 (NVIDIA Grace) compute, Lmod modules, $WORK for installs.
What you end up with
A kernel named Python (R) in the Jupyter kernel picker. Inside it:
%%Rruns a whole cell as R%Rruns a single line of R-i/-opass objects between pandas and R data.frames- R plots render inline
Setup
Run setup-rpy2.sh, or do it by hand as below. Either way, do the env creation on a compute node, not a login node. Installing r-base unpacks tens of thousands of small files and that is slow and antisocial on login1.
1. Install Miniforge (once)
Vista’s python3 module does not include conda, so you install your own. $WORK, not $HOME: conda envs blow past the home quota.
cd $WORK
curl -LO https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-aarch64.sh
bash Miniforge3-Linux-aarch64.sh -b -p $WORK/miniforge3
Note aarch64. Vista is ARM; the x86_64 installer will not work.
Add this to ~/.bashrc so conda is available on every login:
unset PYTHONPATH
source $WORK/miniforge3/etc/profile.d/conda.sh
The unset PYTHONPATH matters. TACC’s python3 module exports PYTHONPATH, and it leaks into conda’s interpreter and causes confusing import errors. Unsetting it only affects that shell; module load python3 brings it back.
2. Create the environment (on a compute node)
idev -p gh -N 1 -n 1 -t 01:00:00
unset PYTHONPATH
source $WORK/miniforge3/etc/profile.d/conda.sh
conda create -y -n rpy2 -c conda-forge r-base rpy2 jupyter ipykernel pandas numpy
conda activate rpy2
conda-forge supplies its own R build, so no module load is needed at any point.
Include pandas and numpy at creation time. Without them rpy2.ipython loads but warns, and the -i / -o DataFrame conversion silently does not work.
3. Register the kernel
python -m ipykernel install --user --name rpy2 --display-name "Python (R)" \
--env R_HOME $CONDA_PREFIX/lib/R
The --env R_HOME flag is the part everyone misses. Jupyter launches the kernel by calling the env’s Python directly; it does not run conda activate, so the env’s bin/ is not on PATH and rpy2 cannot find R. Without it you get:
RuntimeError: Unable to determine R_HOME.
The kernelspec lands in ~/.local/share/jupyter/kernels/rpy2/, which is in $HOME, so it is visible from every compute node.
4. Restart the Jupyter server
Not just the kernel. The Jupyter server caches kernelspecs at startup, so a newly registered or newly edited kernel will not appear (or will launch with stale settings) until you shut the whole session down and start a new one.
On Vista, launch through the TACC Analysis Portal (tap.tacc.utexas.edu) → Jupyter → gh queue, rather than hand-rolling an SSH tunnel.
Then pick Python (R) from the kernel dropdown.
Using it
%load_ext rpy2.ipython
A pure R cell:
%%R
x <- rnorm(100)
y <- 2*x + rnorm(100)
fit <- lm(y ~ x)
summary(fit)
pandas in, R object out:
import pandas as pd
df = pd.DataFrame({"g": ["a","a","b","b"], "v": [1.0, 2.5, 3.0, 4.5]})
%%R -i df -o means
means <- aggregate(v ~ g, data = df, FUN = mean)
means
means # back in Python as a DataFrame
A plot (width/height in inches, -r is DPI):
%%R -w 6 -h 4 --units in -r 150
plot(x, y, pch = 19, col = "steelblue")
abline(fit, col = "red", lwd = 2)
Installing R packages
Prefer conda over install.packages(). CRAN source installs compile from scratch on ARM, which is slow and sometimes fails on packages with C/Fortran dependencies. conda-forge ships prebuilt linux-aarch64 binaries:
conda install -n rpy2 -c conda-forge r-tidyverse r-data.table r-ggplot2
The naming convention is r- plus the lowercased CRAN name. If a package genuinely is not on conda-forge, fall back to install.packages() inside an %%R cell and expect a wait.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
RuntimeError: Unable to determine R_HOME |
Kernel has no R_HOME and the env’s bin/ is not on PATH |
Re-register the kernel with --env R_HOME $CONDA_PREFIX/lib/R, then restart the Jupyter server |
| Kernel changes have no effect | Jupyter server cached the old kernelspec | Shut down the whole Jupyter session, not just the kernel |
UserWarning: pandas is strongly recommended ... No module named 'numpy' |
numpy/pandas missing from the env | conda install -n rpy2 -c conda-forge pandas numpy |
bash: conda: command not found |
Miniforge not on PATH in this shell |
source $WORK/miniforge3/etc/profile.d/conda.sh |
PYTHONPATH warning from the installer |
TACC python3 module leaking into conda |
unset PYTHONPATH |
Module R is unknown |
There is no R module on Vista | Use conda, per this guide |
To confirm what the kernel actually sees, run this as the first cell:
import os
print(os.environ.get("R_HOME"))
print(os.environ.get("PATH"))
R_HOME printing None means the kernelspec fix did not take.
Quick workaround
If you cannot restart the Jupyter server right now, set the variable manually in the first cell, before importing anything:
import os
os.environ["R_HOME"] = os.path.expandvars("$WORK/miniforge3/envs/rpy2/lib/R")
%load_ext rpy2.ipython
This works but has to be repeated in every notebook. The kernelspec fix is the real one.
Notes for later
- Destined to become a GitHub Pages page. Needs Morehouse brand styling (Cayman theme +
style.scssoverride) if it lands undermorehouse-supercomputing. - The
$WORKpaths in the setup script are resolved at runtime, so they are portable across users. - Worth checking whether an Apptainer image would be a lower-friction path for a large cohort, since it skips the per-user conda install entirely.