0

I'm having a common issue with R and am aware the questions has been asked many times before... still having trouble debugging exactly how the error occurs in my code. Hoping someone can help out.

The offending bit of code is as follows:

constraintIndex = which(constraintChoice == getParameters()$constraints)
  loginfo("89: '%s'", constraintIndex) # logs successfully as '4'
  if (constraintIndex <= 0) constraintIndex <- 1
  myConstraints = switch(constraintIndex, noConstraints, sumOneConstraints, nonNegConstraints, allConstraints)

  problem <- Problem(objective, constraints = myConstraints)
  loginfo("97: '%s'", someinfo) # reaches here just fine
  result <- solve(problem)
  loginfo("99: '%s'", someinfo) # never hits this point

Log output:

(previous logging)
INFO::89: '4'
INFO::97: 'someinfo'
INFO::Function returned: {"errorCode":[1],"errorResponse":["missing value where TRUE/FALSE needed"]

So it hits line 97 and logs just fine, but fails at result <- solve(problem)

Resources:

Error in if/while (condition) {: missing Value where TRUE/FALSE needed

R - " missing value where TRUE/FALSE needed "

"missing value where TRUE/FALSE needed" Error in if statement in R

Once again, I'm aware it's been asked but still do not have enough info to solve my problem.

8t12c7081
  • 683
  • 3
  • 9
  • 30
  • Very hard to say without a reproducible example, but are you sure that `zeroConstantTerm` is a string value? Or is it missing, NULL, or NA? – jdobres Jul 17 '19 at 22:38
  • @jdobres i have tried setting zeroConstantTerm manually to "No" above that line without any change in behavior – 8t12c7081 Jul 17 '19 at 22:48
  • In fact, by placing a `loginfo(zeroConstantTerm)` after 89 I can see it returns 'Yes'. Now I have placed a logger on each line to find where the script exits and determined it is failing on `result <- solve(problem)`. I don't see this function anywhere in the code so not sure how to proceed – 8t12c7081 Jul 17 '19 at 22:53
  • 1
    `zeroConstantTerm` doesn't seem to defined anywhere which probably leads to error in `if (zeroConstantTerm == "No")`. – Shree Jul 18 '19 at 00:47
  • @Shree I've updated the question - this var is defined earlier in the script and I have verified it is not NA at this point. Question edited to focus on the line that is causing the exit – 8t12c7081 Jul 18 '19 at 13:11

0 Answers0