[R] monitor variable change

Rainer M Krug r.m.krug at gmail.com
Wed Feb 16 15:11:16 CET 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 02/16/2011 03:04 PM, 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()
You can replace the previous line by:

browser(expr=(a!=old.a)

see ?browser for details.

> }
> 
> 
> Another solution is to write your output to file (using sink for
> example) and to watch this file using a tool like tail.
> 
> Jan
> 
> 
> 
> 
> 
> 
> Quoting Alaios <alaios at yahoo.com>:
> 
>> I think we are both talking for watchpoints-breakpoints
>>
>> --- On Wed, 2/16/11, Rainer M Krug <r.m.krug at gmail.com> wrote:
>>
>>> From: Rainer M Krug <r.m.krug at gmail.com>
>>> Subject: Re: [R] monitor variable change
>>> To: "Alaios" <alaios at yahoo.com>
>>> Cc: R-help at r-project.org
>>> Date: Wednesday, February 16, 2011, 9:54 AM
> On 02/16/2011 10:38 AM, Alaios wrote:
>> Dear all I would like to ask you if there is a way in
> R to monitor in R when a value changes.
> 
>> Right now I use the sprintf('my variables is %d \n, j)
> to print the value of the variable.
> 
>> Is it possible when a 'big' for loop executes to open
> in a new window to dynamically check only the variable I
> want to.
> 
> I don't think that this functionality is implemented.
> 
> But I guess you can implement it - would it be possible to
> re-define th
> "<-" to check if a certain variable is to be changed,
> and then print it?
> 
> Might be tricky and would slow everything considerably
> down.
> 
> Just a thought,
> 
> Rainer
> 
> 
>> If I put all the sprintf statements inside my loop
> then I get flooded with so many messages that makes it
> useless. 
> 
>> Best Regards
>> Alex
> 
>> ______________________________________________
>> 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.
> 
> 
>>>
>>
>>
>>
>>
>> ______________________________________________
>> 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.
>>

- -- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Tel:        +33 - (0)9 53 10 27 44
Cell:       +27 - (0)8 39 47 90 42
Fax (SA):   +27 - (0)8 65 16 27 82
Fax (D) :   +49 - (0)3 21 21 25 22 44
Fax (FR):   +33 - (0)9 58 10 27 44
email:      Rainer at krugs.de

Skype:      RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1b2wQACgkQoYgNqgF2ego2XwCfbGgvNHskD1GI+fIO+wB0vvw0
aDAAnigi9/D1abrquA0sIOWdPHS9rEAl
=F71G
-----END PGP SIGNATURE-----



More information about the R-help mailing list