-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
If someone creates an equation that references variables that don't exist, this should not cause a catastrophic error, but should result in very stern warnings to the user. Default values of 0.0 should be set for any missing var.
- Each variable should be checked at start of simulation, maybe init() method or preStep() first time (see code below)
- Handle bad values after init(): Current behavior uses tryCatch() and proceeds without failing, but is less descriptive than the proposed approach would yield. See: R implementation of modelObject, modelSubObject and basic equation object OM #55
Pre Evaluation of Present Variables in init()
Consider this snippet of code, where for_suro is DEFINED, but pas_suro is UNDEFINED in the array data:
data <- list(
for_suro = 1.1
)
eqstring <- 'for_suro + pas_suro'
eqx <- parse(text=eqstring)
eval(eqx, data)
Error in eval(eqx, data) : object 'pas_suro' not found
We should be able to use getParseData(), which returns the following info about our expression:
eqinfo = getParseData(eqx)
line1 col1 line2 col2 id parent token terminal text
7 1 1 1 19 7 0 expr FALSE
1 1 1 1 8 1 3 SYMBOL TRUE for_suro
3 1 1 1 8 3 7 expr FALSE
2 1 10 1 10 2 7 '+' TRUE +
4 1 12 1 19 4 6 SYMBOL TRUE pas_suro
6 1 12 1 19 6 7 expr FALSE
To extract those variables that are requested, we can use:
eqvars <- eqinfo[eqinfo$token == "SYMBOL",]
eqvars
line1 col1 line2 col2 id parent token terminal text
1 1 1 1 8 1 3 SYMBOL TRUE for_suro
4 1 12 1 19 4 6 SYMBOL TRUE pas_suro
And then set defaults appropriately, perhaps at the "getInputs()" method of the Equation class.
Metadata
Metadata
Assignees
Labels
No labels