Model systems as stock-and-flow models in R. Stock-and-flow modelsare foundational to system dynamics, and help to understand systemscomplicated by nonlinearities, delays, and feedback loops. sdbuildR aimsto make stock-and-flow modeling accessible and effortless, enabling youto dedicate your expertise to what matters most: building insightful,high-quality models. Get started athttps://kcevers.github.io/sdbuildR/!
All package capabilities are described in the vignettes:
The release version can be installed from CRAN:
install.packages("sdbuildR")The development version can be installed from GitHub:
if (!require("remotes"))install.packages("remotes")remotes::install_github("KCEvers/sdbuildR")sdbuildR offers two simulation engines: R and Julia (supported byJuliaConnectoR).If you would like to run ensemble simulations and use units, you willneed to install and set up the Julia environment. Seethisvignette for guidance.
To cite sdbuildR, please use:
citation("sdbuildR")#> To cite package 'sdbuildR' in publications use:#>#> Evers K (2025). _sdbuildR: Easily Build, Simulate, and Visualise#> Stock-and-Flow Models_. R package version 1.0.7.9000,#> https://github.com/KCEvers/sdbuildR,#> <https://kcevers.github.io/sdbuildR/>.#>#> A BibTeX entry for LaTeX users is#>#> @Manual{,#> title = {sdbuildR: Easily Build, Simulate, and Visualise Stock-and-Flow Models},#> author = {Kyra Caitlin Evers},#> year = {2025},#> note = {R package version 1.0.7.9000, https://github.com/KCEvers/sdbuildR},#> url = {https://kcevers.github.io/sdbuildR/},#> }Unlike in other system dynamics software, sdbuildR provides onlyminimal support for non-negative stocks and flows. Specifically, settingstocks to non-negative will constrain the stocks to remain non-negative,but will not adjust the corresponding flows. In any case, enforcingeither stocks or flows to be non-negative is not recommended, as it maymask model misspecification. Stocks and flows that logically cannot benegative (e.g., animals or deaths) should ideally remain non-negative asa result of the model’s equations and parameters, rather than by forcingthem to be non-negative.
sdbuildR does not support vectorized operations, destructuringassignment, or minimum and maximum constraints for variables.
sdbuildR does not support the Insight Maker functions Stop(),Prompt(), Confirm(), Pause(), Fix(), Map(), Filter(), and Repeat(), northe delay and past functions. A message is issued if any of these aredetected.
sdbuildR is heavily based on common system dynamics software such asVensim,Powersim,Stella, andInsight Maker. To translate xmilemodels to R, see the R packagereadsdr. To buildstock-and-flow models with the R packagedeSolve, the bookSystemDynamics Modeling with R by Jim Duggan will prove useful. In Python,stock-and-flow models are supported byPySD.
sdbuildR is under active development. While thoroughly tested, thepackage may have bugs, particularly in complex model translations. Weencourage users to reportissues on GitHub -your input helps the package improve! Usedebugger() todiagnose model errors, and use the vignettes for guidance.