Skip to contents

Macros are global variables or functions that can be used throughout your stock-and-flow model. macro() adds, changes, or erases a macro.

Usage

macro(sfm, name, eqn = "0.0", doc = "", change_name = NULL, erase = FALSE)

Arguments

sfm

Stock-and-flow model, object of class sdbuildR_xmile.

name

Name of the macro. The equation will be assigned to this name.

eqn

Equation of the macro. A character vector. Defaults to "0.0".

doc

Documentation of the macro. Defaults to "".

change_name

New name for macro (optional). Defaults to NULL to indicate no change.

erase

If TRUE, remove macro from the model. Defaults to FALSE.

Value

Updated stock-and-flow model

Examples

# If the logistic() function did not exist, you could create it yourself:
sfm = xmile() %>%
macro("logistic", eqn = "function(x, slope = 1, midpoint = .5) 1 / (1 + exp(-slope*(x-midpoint)))")
#> Warning: Names were changed to be syntactically valid and/or avoid overlap: logistic -> logistic_1