Appendix A — Installation

Package installation is hard, let’s go shopping.

A.1 Packages

The short version:

install.packages(
  c("monty", "dust2", "odin2"),
  repos = c("https://mrc-ide.r-universe.dev", "https://cloud.r-project.org"))

We require a number of R packages, most of which are currently (as of late 2024) under very active development. The canonical source for these packages is currently our r-universe and not CRAN, but we hope to get the stack onto CRAN as soon as they stabilise. The version of odin on CRAN is now wildly out of date with the content in this guide.

The required packages are:

  • odin2: the DSL itself
  • dust2: support for running odin models (odin “transpiles” R code into dust2)
  • monty: statistical distributions and inference support

These packages sit on a huge foundation of work, much of which has been written by staff at Posit (formerly RStudio)

  • cpp11 for painless bindings between C++ and R
  • pkgbuild for building packages
  • pkgload for loading temporary packages
  • cli for messages and console interfaces
  • rlang for control over metaprogramming and errors

A.2 System requirements

You need a functioning C++ toolchain. How you get one depends on your platform, and is unfortunately a bit of a moving target. The source of truth for these matters is Writing R extensions and R installation and administration.

For windows users it is usually sufficient to install Rtools for your version of R. For Linux users there’s a good chance you already have a functioning toolchain. Mac users tend to have the biggest issues, particularly with OpenMP support.

You can run this diagnostic function in pkgbuild (which we use to do compilation) to help diagnose your system

pkgbuild::check_build_tools(debug = TRUE)
Trying to compile a simple C file
Running /opt/R/4.4.1/lib/R/bin/R CMD SHLIB foo.c
using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’
gcc -I"/opt/R/4.4.1/lib/R/include" -DNDEBUG   -I/usr/local/include    -fpic  -g -O2  -c foo.c -o foo.o
gcc -shared -L/opt/R/4.4.1/lib/R/lib -L/usr/local/lib -o foo.so foo.o -L/opt/R/4.4.1/lib/R/lib -lR
Your system is ready to build packages!