Part IV is the programmer’s guide to NIMBLE. At the heart of programming in NIMBLE are nimbleFunctions. These support two principal features: (1) a setup function that is run once for each model, nodes, or other setup arguments, and (2) run functions that will be compiled to C++ and are written in a subset of R enhanced with features to operate models. Formally, what can be compiled comprises the NIMBLE language, which is designed to be R-like.

This part of the manual is organized as follows:

  • Chapter 11 describes how to write simple nimbleFunctions, which have no setup code and hence don’t interact with models, to compile parts of R for fast calculations. This covers the subset of R that is compilable, how to declare argument types and return types, and other information.
  • Chapter 12 explains how to write nimbleFunctions that can be included in BUGS code as user-defined distributions or user-defined functions.
  • Chapter 13 introduces more features of NIMBLE models that are useful for writing nimbleFunctions to use models, focusing on how to query model structure and carry out model calculations.
  • Chapter 14 introduces two kinds of data structures: modelValues are used for holding multiple sets of values of model variables; nimbleList data structures are similar to R lists but require fixed element names and types, allowing the NIMBLE compiler to use them.
  • Chapter 15 draws on the previous chapters to show how to write nimbleFunctions that work with models, or more generally that have a setup function for any purpose. Typically a setup function queries model structure (Chapter 13) and may establish some modelValues or nimbleList data structures or configurations (Chapter 14). Then run functions written in the same way as simple nimbleFunctions (Chapter 11) along with model operations (Chapter 13) define algorithm computations that can be compiled via C++.