0

Sorry that this is quite vague but I'd have to post 100's of lines of proprietary code which I cannot do.

Some R code I've written calls a moderately complicated R function I also wrote. The code, or really the function, seems to fail when I pass an odd-sized block of data to it, but all that happens is R drops out of the function without a return value and prints this message:

  Error in if (range[2] - range[1] == 1) return(c(range[1], range[2])) : 
  missing value where TRUE/FALSE needed

Nothing in my function has anything like

  'range[2] - range[1] == 1'

so I assume this is actually generated in some lower level R function but I don't know how to get R to be more clear about where the failure is. I've looked at what's getting passed to my function at the top level and it looks good so the problem is presumably somewhere lower. I'd guess this is caused by some sort of

  '(NA - value) ==1' 

failing due to the NA but that's just a guess.

How might I get R to be more clear about where the failure is actually occurring, short of print statements line by line in the function? I suspect that tryCatch might be part of the solution but it's not clear to me where I put this. Do I wrap my upper call in a tryCatch or do I place it in the lower function and move it around until it finds something?

Very unclear!

user2510479
  • 1,528
  • 13
  • 17
LGTrader
  • 2,349
  • 4
  • 23
  • 29
  • In addition to Joshua's suggestion for general debugging problems, you may want to look at this question: http://stackoverflow.com/q/7355187/892313 – Brian Diggs Aug 14 '13 at 19:27
  • 2
    I find some combination of `traceback()`, `options(error=recover)`, and `debug()` to be most helpful. – Ellis Valentiner Aug 14 '13 at 19:29
  • Thanks to those who answered and provided pointers. As Ellis states above, and as is stated in the links, traceback() & options(error=recover) got me to the line that's failing and browsing the inputs to the call to earth demonstrates at least why the failure exists. I still need to debug the problem but my needs are well answered here. – LGTrader Aug 14 '13 at 21:10
  • As there are no 'answers' (only comments) there's no way for me to credit any specific response. – LGTrader Aug 14 '13 at 21:11

0 Answers0