# readsdr

## Overview

The goal of readsdr is to bridge the design capabilities from specialised System Dynamics software with the powerful numerical tools offered by R libraries. The package accomplishes this goal by parsing .xmile files (Vensim and Stella models) into R objects to construct networks (graph theory), ODE functions for deSolve and Stan.

## Installation

You can install the released version of readsdr from CRAN with:

`install.packages("readsdr")`

And the development version from GitHub with:

```
# install.packages("devtools")
devtools::install_github("jandraor/readsdr")
```

## Usage

```
library(readsdr)
filepath <- system.file("models/", "SIR.stmx", package = "readsdr")
mdl <- read_xmile(filepath)
summary(mdl)
#> Length Class Mode
#> description 4 -none- list
#> deSolve_components 4 -none- list
#> graph_dfs 2 -none- list
```

For reading Vensim models, they must be exported as .xmile.

For information on how to use this package, see the vignette or type `vignette("Introduction_to_readsdr")`

in R.

## Supported builtins

**Stella**
- Comparison operators (
`=`

, `<>`

)
- Logical operators (
`AND`

, `OR`

, `NOT`

)
`If Else Then`

- Inequality operators (
`<`

, `>`

)
`Pulse`

^{1}
`Step`

^{1}
- Endogenous table functions
- Smoothing functions:
`SMTH1`

, `SMTH3`

, `SMTHN`

- Limited support to
*uni-dimensional* arrays. *Apply all* translation is restricted to numeric values.
- Math functions:
`ABS`

, `SQRT`

- Stats functions:
`NORMAL`

**Vensim**
- Comparison operators (
`=`

, `<>`

)
- Logical operators (
`:AND:`

, `:OR:`

, `:NOT:`

)
`IF_THEN_ELSE`

- Inequality operators (
`<`

, `>`

)
`Pulse`

^{1}
`Pulse Train`

^{1}
`Step`

^{1}
- Endogenous table functions
- Smoothing functions:
`SMOOTH`

, `SMOOTH3`

, `SMOOTH3I`

, `SMOOTHI`

- Math functions:
`ABS`

, `SQRT`

^{1} Restricted to Euler integration.

## Notes

*uniflow* and *non-negative* stock features from *Stella* are **not** supported.

No built-in is supported for translations to *Stan* code.

Modules from *Stella* are **not** supported.

## Acknowledgments

Thanks to:

- Rogelio Oliva for advocating the need to create an open-source tool for the System Dynamics community and push forward this endeavour.
- Sergey Naumov for his ideas to implement several functions in this package.
- Jim Duggan from whom I borrowed ideas to implement this package.

## References

Duggan, J. (2016). *System Dynamics Modeling with R*. Springer.