[R] Debugging a hanging function within R

Yan Wong h.y.wong at leeds.ac.uk
Fri Nov 16 12:58:27 CET 2007


Hi,

I have an R program which takes several days to run, and sometimes  
hangs while running, presumably stuck in some sort of loop within a  
package function. I don't know where in the program code it is  
hanging: it is likely to be within a routine that is iterated many  
hundreds of thousands of times, each time with different random  
numbers used.

I'd like to debug the R code, but I can't simply set a breakpoint on  
the function, as it works fine for the first n-thousand times. What  
I'd really like to do is to interrupt the running program once it has  
hung, then step into the function, examining the variables as I go.

I can't seem to find a way to do this (i.e. interrupt a routine at an  
arbitrary time during its run, then step into it using the debugger).  
Is it possible?

Apologies if this is answered in the manuals, but I've had a trawl  
through and can't seem to find how to do it. I have tried attaching  
to the process using gdb, but then don't know how to issue gdb  
commands to invoke the R debugger in the stopped R session.

Thanks

Yan

(n.b. R 2.5.1 on OS X, if that is relevant)



More information about the R-help mailing list