[R] MakeActiveBinding help needed

Carl Witthoft carl at witthoft.com
Wed Jan 6 23:30:07 CET 2010


Hi,
I wanted a Q&D way to open a new graphics window but keep the focus in 
the console window (under Windows and the Rgui), so I wrote a line into 
my Rprofile.site file as follows:

invisible(makeActiveBinding('newdev', function(...) 
dev.new(restoreConsole=T), .GlobalEnv))

(That is all on one line, incase the mailer re-parses it). This gives me 
a command "newdev" which does not require me to enter a pair of 
parentheses to execute it.

This worked just fine so far as the command goes.  Here's the problem: 
this definition is stored as part of my .Rdata file, and the next time I 
start up R, I get a crash.   I tracked that down to an odd fact:  while 
R is loading this definition from .Rdata, it tries to execute the 
command, i.e. open a graphics window!  Since the graphics library hasn't 
been loaded yet, crash happens.

I re-wrote my definition to

invisible(makeActiveBinding('newdev', function(...) {library(graphics); 
dev.new(restoreConsole=T)}, .GlobalEnv))

and then R booted up just fine, except that two new graphics windows 
were created -- one from loading "newdev" from .Rdata and one from 
executing the Rprofile script with the "newdev" definition in it.

So my question is:  is there some way I can define this 
makeActiveBinding item without R trying to execute it at the point of 
loading (either from Rprofile or from .Rdata)?

thanks
Carl



More information about the R-help mailing list