View source: R/csm_render_model.R
| csm_render_model | R Documentation |
Render a defined Cropping System Model (CSM)
csm_render_model(
model,
name = "dy_dt",
output_type = c("function", "code"),
language = c("R", "Rcpp"),
arg_alias = NULL,
insert_functions = NULL
)
model |
a list vector containing a CSM as created by
|
name |
name of the resulting function |
output_type |
a character value indicating the type of output to produce; one of: "function" (a callable function) or "code" (computer code for the model) |
language |
a character value indicating which programming language into which to render the model |
arg_alias |
an optional named character vector whose names indicate variables for which to use an alias within the generated function and whose elements provide the corresponding alias |
insert_functions |
an optional list of functions to add to rendered code |
Either an R function object (if output_type="function") or a character
vector of model code (if output_type="code") in the programming language
specified by language.
# Define state variables
lv_state <- csm_create_state(
c("x", "y"),
definition = c("prey", "predator"),
units = c("rabbits per square km", "foxes per square km"),
expression(~alpha*x-beta*x*y, ~delta*x*y-gamma*y))
# Define parameters
lv_parameters <- csm_create_parameter(
c("alpha", "beta", "gamma", "delta"),
definition = c("maximum prey per capita growth rate",
"effect of predator population on prey death rate",
"predator per capita death rate",
"effect of prey population on predator growth rate"),
units = c("rabbits per rabbit", "per fox",
"foxes per fox", "foxes per rabbit"))
# Define model
lotka_volterra_model <-
csm_create_model(
state = lv_state,
parms = lv_parameters)
# Render model into raw R code
lotka_volterra_code <-
csm_render_model(lotka_volterra_model,
output_type = "code",
language = "R")
# Render model into a callable R function
lotka_volterra_fun <-
csm_render_model(lotka_volterra_model,
output_type = "function",
language = "R")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.