[R] Debugging a hanging function within R
Yan Wong
h.y.wong at leeds.ac.uk
Fri Nov 16 16:10:46 CET 2007
On 16 Nov 2007, at 15:05, Gabor Grothendieck wrote:
> Try this:
>
> f <- function() {
> for(i in 1:1000) {
> if (i == 50) browser()
> print(i)
> }
> }
>
> # enters debugger when i is 50.
> # n/c/Q will step one statement/continue/Quit respectively
> f()
Thanks. The problem is that I don't know when it will hang, so I
don't know under which conditions I should invoke the browser (e.g.
in your code I don't know if it is on the 50th iteration, or the
500th that I wish to exit to the debugger). To find out would require
running it again using the same random seed and outputting the loop
number each time, which I'd prefer not to do, given that it takes a
few days of running the program to get to this point.
Cheers
Yan
More information about the R-help
mailing list