[R] monitor variable change

Jan van der Laan rhelp at eoos.dds.nl
Wed Feb 16 15:04:02 CET 2011


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.

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
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> 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.
>>
>>
>> - --
>> 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/
>>
>> iEYEARECAAYFAk1bnsoACgkQoYgNqgF2egr53gCffKAK4FnRxm/H371ANg8ONs6E
>> NF8AoIyIGoAsdWu6a0HpE0BPqVD0fV+n
>> =1MOY
>> -----END PGP SIGNATURE-----
>>
>
>
>
>
> ______________________________________________
> 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