[R] set breakpoint in debug
Duncan Murdoch
murdoch.duncan at gmail.com
Mon Sep 16 21:20:37 CEST 2013
On 16/09/2013 3:05 PM, Hui Du wrote:
> Hi All,
>
> I need some help regarding how to set up a breakpoint in debug. For example, I have a very simple/naïve function (a useless function just for demo)
>
> f = function()
> {
> x = 10;
> len = 100;
>
> a = 1;
> for(i in 1:len)
> {
> a = a * i;
> }
>
> y = x + a;
> y;
> }
>
>
> If I need to debug it, I can run debug(f). After I go into the debugger, if I want to skip the loop and stop in the statement y = y + a, directly, how to do that? I know R has a function named setBreakpoint but I have never used it correctly.
After you have gone into the debugger, it's too late. setBreakpoint
works by modifying the body of the function, and the evaluator has
already retrieved the body of the function when you enter.
You can set a breakpoint in a function that is not executing from the
top level or from the debugger, and it will stop there on the next
invocation. The syntax is something like:
setBreakpoint("filename.R#11")
assuming that the spot where you want to stop is line 11 in the source
file filename.R where your function came from. (In July at useR 2013
the RStudio folks were demonstrating a GUI that did the same sort of thing.)
It has been requested that setBreakpoint should be able to work on the
active function as well as inactive ones, and there is no fundamental
reason why that would be impossible, but it is tricky to manipulate
expressions in the middle of evaluating them, so that's not in place (yet?).
Duncan Murdoch
>
> Your help is highly appreciated.
>
> HXD
>
> [[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list