Using R, Python, and CmdStan
This workstation supports scientific computing with R, Python, and CmdStan.
Software is mainly managed using Miniforge, Conda, and Mamba.
1 Main idea
The workstation separates software into different levels:
| Level | Example | Who manages it? |
|---|---|---|
| System software | Slurm, Quarto, LaTeX, system libraries | Administrator |
| Shared conda environments | R-4.4, py311 |
Administrator/RSE team |
| Project R packages | renv project library |
Project users |
| Personal packages | user home directory | Individual user |
For R projects, the recommended approach is:
shared conda R version + project-specific renv library
This means everyone may use the same R version from conda, but each serious project can keep its own R package versions using renv.
2 Check conda
which condaIf conda is available, this should show a path.
3 List available environments
conda env listor:
mamba env list4 Activate an environment
Example for R:
conda activate R-4.4Example for Python:
conda activate py311The exact environment names depend on what has been installed.
5 Deactivate an environment
conda deactivate6 R
Activate the R environment:
conda activate R-4.4Start R:
RRun an R script:
Rscript analysis.RCheck the R package library paths:
.libPaths()7 Where should R packages be installed?
For most users:
- quick personal tests can use the personal R library
- reproducible project work should use
renv - shared packages for all users should be installed by the administrator in the shared conda environment
Do not assume that installing an R package in your own account makes it available to other users.
See R Package Management for the full policy.
8 Python
Activate a Python environment:
conda activate py311Start Python:
pythonRun a Python script:
python analysis.pyInstall Python packages using conda or mamba when possible:
mamba install numpy pandas scipy matplotlibFor project-specific work, consider creating a project-specific environment.
9 CmdStan
CmdStan is useful for users who prefer CmdStan or CmdStanR rather than RStan.
Check whether CmdStan is available:
ls /data/softwareIf using CmdStanR in R:
library(cmdstanr)
cmdstanr::cmdstan_path()Set CmdStan path if needed:
cmdstanr::set_cmdstan_path("/data/software/cmdstan")10 Recommended workflow for R + CmdStanR projects
cd /data/projects/my-stan-project
conda activate R-4.4
RInside R:
install.packages("renv")
renv::init()
install.packages("cmdstanr")
cmdstanr::set_cmdstan_path("/data/software/cmdstan")
renv::snapshot()For future work in the same project:
cd /data/projects/my-stan-project
conda activate R-4.4
RThen inside R:
renv::restore()11 Recommended workflow
For reproducible projects:
- keep scripts in a project folder
- activate the correct conda environment
- use
renvfor R package versions - run long jobs through Slurm
- save outputs to
results/ - use Git when possible
12 Example environment note
Create a file called environment-notes.txt in your project folder:
Date: 2026-06-18
Workstation: mod-linux-ws01
Environment: R-4.4
R package management: renv
Main packages: tidyverse, cmdstanr, posterior