Skip to content
Prev 26137 / 398502 Next

RGnumeric real time refresh?

That's a very nice example of a general concept that I have hoped we
might get to. There are a variety of ways to approach this issue.
While slightly abstract/apparently indirect, using the Gnumeric/Gtk
event loop is probably the easiest way to think about things and you
can interact with it using the RGtk package.

At its simplest, if you really knew that there was more data arriving
each and every 7 seconds, you could register a timer action with the
Gnumeric event loop using the gtkAddTimeout() function in theRGtk
package.  Here's a function a that one can call from Gnumeric which
arranges for the function f (defined inside this function) to be
called every interval milli-seconds.  That function f generates a
single normal observation and puts it in a cell ( A1 by default)
and forces the entire workbook to be updated.

setTimer <-
function(interval, r = 1, c = 1, .sheet) {
 library(RGtk)

 f <-
   function() {
     .sheet[r, c] <- rnorm(1, mean = 10)
     recalcBook(getGnumericWorkbook(.sheet))
     return(FALSE)
   }
 
 gtkAddTimeout(interval, f)
}

gnumeric.registerFunction(
      setTimer, "setTimer", "fff", "garbage", "Set a timer to fire each interval")
      
So you can then call this from within a Gnumeric cell as

  =setTimer(7000, 1, 1)

and it will just continue to update.

(The return(FALSE) at the end of f() is slightly unintuitive. It says
don't renew the timer action. Why? Because recalculating the sheet
will reset the timer when the =setTimer(..) cell is re-evaluated).


That's how you can do things with timers.  If the data is coming from
one of a collection of connection types (e.g. FIFOs, sockets, etc.) we
might register an S function that is invoked each time more data
becomes available.  In other words, we would put an event handler on
the connection. At present, this is not possible to do in regular R.
I have written code that implements it but never committed it for a
variety of reasons. Perhaps I will do so soon.

 Thanks for the application. This is one of the more interesting cases
which motivated the RGtk package.

 D.
Richard Spady wrote:

  
    
Message-ID: <20021210063608.D3090@jessie.research.bell-labs.com>
In-Reply-To: <3DF53664.8234A72A@nwu.edu>; from r-spady@nwu.edu on Mon, Dec 09, 2002 at 06:33:40PM -0600