Skip to content

Check Components for Missing Inputs at preStep() or init(), handle missing values gracefully #21

@rburghol

Description

@rburghol

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.

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions