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 conda

If conda is available, this should show a path.

3 List available environments

conda env list

or:

mamba env list

4 Activate an environment

Example for R:

conda activate R-4.4

Example for Python:

conda activate py311

The exact environment names depend on what has been installed.

5 Deactivate an environment

conda deactivate

6 R

Activate the R environment:

conda activate R-4.4

Start R:

R

Run an R script:

Rscript analysis.R

Check 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 py311

Start Python:

python

Run a Python script:

python analysis.py

Install Python packages using conda or mamba when possible:

mamba install numpy pandas scipy matplotlib

For 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/software

If using CmdStanR in R:

library(cmdstanr)
cmdstanr::cmdstan_path()

Set CmdStan path if needed:

cmdstanr::set_cmdstan_path("/data/software/cmdstan")

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