[R] monitor variable change

Duncan Murdoch murdoch.duncan at gmail.com
Wed Feb 16 16:09:30 CET 2011


On 16/02/2011 9:04 AM, Jan van der Laan wrote:
> One possible solution is to use something like:
>
> a<- 0
> for (i in 1:1E6) {
>       old.a<- a
>
>       # do something e.g.
>       a<- runif(1)<  1E-6
>
>       if (a != old.a) browser()
> }
>
>
> Another solution is to write your output to file (using sink for
> example) and to watch this file using a tool like tail.


The trace() function provides this kind of thing temporarily, with a lot 
of flexibility.  setBreakpoint() provides a slightly more friendly way 
to construct arguments to it -- you can say to set the breakpoint at 
line 7, not having to work out that line 7 is the 3rd statement within 
the 2nd statement block in the function.

Duncan Murdoch



More information about the R-help mailing list