sdInitEquations: Initialize R-format Equations from a List of Strings or...

Description Usage Arguments Details Value Examples

Description

Initialize a list of equations from a list of strings or R-expressions with the equations in R-format and sort the equations using their interdependencies to enable the reuse of evaluated equations in other equations further in the list. Abort if any circular dependency is found and warn the user. Each equation will be an element of the returned sorted list in R-expression format. Use the eval function to evaluate each R-expression in a specified environment.

Usage

1
sdInitEquations(equations, separator = "<-", eqName = c("aux", "eq"))

Arguments

equations

A list of strings or R-expressions with the equations in R-format.

separator

The assignment symbol used in the equations strings. Default is "<-".

eqName

The name of the list that will be initialized and sorted, e.g. 'aux' for sdModelClass auxiliary equations and/or 'eq' for sdStaticModelClass algebraic equations.

Can be a vector with all the equations list names that should be considered in the sorting. Default is c('aux', 'eq').

Details

The returned list of equations can be: added to the auxiliary equations list of a sdModelClass object to replace the use of functions to calculate intermediary values of the model's system of differential equations; or added to the algebraic equations of a sdStaticModelClass object.

Value

A sorted list of equations in R-expression format.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
const = list(c1 = 2, c2 = 1)
vars = list(k1 = 10, k2 = 2)

auxEquationsStrings <- list("cDiffFrac <- (const$c1 - const$c2) / aux$kDiff",
                            kDiff = "vars$k1 - vars$k2")
aux <- sdInitEquations(auxEquationsStrings, eqName = 'aux')

print(aux)
#> $kDiff
#> expression(vars$k1 - vars$k2)
#>
#> $cDiffFrac
#> expression((const$c1 - const$c2) / aux$kDiff)

aux$kDiff <- eval(aux$kDiff)
print(eval(aux$cDiff))
#> [1] 0.125

EmbrapaInformaticaAgropecuaria/sdsim documentation built on May 10, 2019, 9:58 a.m.