0

I am having trouble while debugging my code. The code is shown below. So, within my lapply function there is something going wrong. To determine the bug I am writing the three params into a global variable. But what happing is the following: The list length (within the first print) is always 3 (as it should be), also in the second print, foo has length 3. Perfect. After these lines, the bug occurs, execution breaks and when I then take a look at my variable foo, it has length 4 and only the vl variable occurs within foo. I have no other allocation of foo somewhere else in my code, also this is the only global variable I am using.

What am I missing? I can't explain myself this behaviour.

With best regards,

Mario

.evalModel = function(model, vl, params){
  print(length(list(model, vl, params)))
  foo<<-list(model, vl, params)
  print(length(foo))
  modelPerformance = lapply(model, function(x){
    ruleResults = vector(mode="list", length = length(x) )
    for(i in 1:length(x)){
      if(class(x[[i]]) == "rule"){
        ruleResults[[i]] = .evalRule(x[[i]] , vl, params)
      } else{
        ruleResults[[i]] = .evalRule(x[[i]]$rule , vl, params)
      }
    }
    ruleResults
  })
  class(modelPerformance) = "GP-Model"
  return(modelPerformance)
}

1 Answers1

0

Put browser() after modelPerformance line, rerun the definition of the function and run the function. You will be 'sitting' inside the lapply call and you'll be able to step through each line, examine the objects and see what's going on. Extensive debugging options are described here: General suggestions for debugging in R

Community
  • 1
  • 1
Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197