-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 02/16/2011 03:29 PM, Hadley Wickham wrote: > One way to implement this functionality is with a task manager callback: > > watch <- function(varname) { > old <- get(varname) > > changed <- function(...) { > new <- get(varname) > if (!identical(old, new)) { > message(varname, " is now ", new) > old <<- new > } > TRUE > } > invisible(addTaskCallback(changed)) > } > > a <- 1 > watch("a") > a <- 2
Wow - I was looking for something like that for a long time - this is absolutely perfect for debugging. I guess I will use it quite often. Thanks, Rainer > > > Hadley > > On Wed, Feb 16, 2011 at 9:38 AM, Alaios <ala...@yahoo.com> 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. >> >> 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@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: rai...@krugs.de Skype: RMkrug -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEUEARECAAYFAk1b4+4ACgkQoYgNqgF2egp5sQCVEey8FukKl5tLxpnNHwelKoWj YACbBAX9pw9yGT7RRSi9hMU7qQ4Dv2o= =05Mi -----END PGP SIGNATURE----- ______________________________________________ R-help@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.