Learn R Programming

SimInf (version 11.1.0)

C_code: Extract the C code from a SimInf_model object

Description

This function extracts the C source code associated with the model. The code may have been automatically generated by mparse or manually provided by the user during model creation. It is useful for inspecting the implementation, debugging complex propensity functions, or verifying the code used in the simulation.

Usage

C_code(model)

Value

A character vector where each element corresponds to a line of the C source code stored in the model.

Arguments

model

The SimInf_model object to extract the C code from.

Examples

Run this code
## Extract code from an mparse-generated SIR model.
## Using writeLines formats the character vector output for
## readability.
model <- mparse(
  transitions = c("S -> beta * S * I/(S + I + R) -> I",
                  "I -> gamma * I -> R"),
  compartments = c("S", "I", "R"),
  gdata = c(beta = 0.16, gamma = 0.077),
  u0 = data.frame(S = 99, I = 1, R = 0),
  tspan = 1:10,
  use_enum = TRUE
)

writeLines(C_code(model))

Run the code above in your browser using DataLab