Skip to contents

Create R code to rebuild an existing stock-and-flow model. This may help to understand how a model is built, or to modify an existing one.

Usage

get_build_code(sfm, format_code = TRUE)

Arguments

sfm

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

format_code

If TRUE, format the R script with the styler package; only works if language is set to "R" in sim_specs. Defaults to TRUE.

Value

String with code to build stock-and-flow model from scratch.

Examples

sfm = xmile("SIR")
get_build_code(sfm)
#> Warning: Could not use `colored = TRUE`, as the package prettycode is not installed.
#> Please install it if you want to see colored output or see
#> `?styler::print.vertical()` for more information.
#> sfm <- xmile() %>%
#>   sim_specs(stop = "20.0", saveat = "0.01", seed = NULL) %>%
#>   header(name = "Susceptible-Infected-Recovered (SIR)", caption = "My Model Description", created = Sys.time(), author = "Me", version = "1.0", URL = "", doi = "") %>%
#>   build("Susceptible", "stock", eqn = "99999") %>%
#>   build("Infected", "stock", eqn = "1") %>%
#>   build("Recovered", "stock") %>%
#>   build("Total_Population", "constant", eqn = "100000") %>%
#>   build("Effective_Contact_Rate", "constant", eqn = "2") %>%
#>   build("Delay", "constant", eqn = "2") %>%
#>   build("Beta", "aux", eqn = "Effective_Contact_Rate / Total_Population") %>%
#>   build("Lambda", "aux", eqn = "Beta * Infected") %>%
#>   build("Infection_Rate", "flow", eqn = "Susceptible * Lambda") %>%
#>   build("Recovery_Rate", "flow", eqn = "Infected / Delay")