Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inhibit focus stealing when launching a new graphics plot in r

Tags:

r

I am familar with matlab, but relatively new to r. I have an r script which produces many different graphical plot windows and takes some time in between each one. While this is running, I tend to be working on other things. The problem is every time a new graphics window is produced, it steals the focus, redirecting keyboard input away from what i am doing. Is there a way in r to prevent focus stealing when a graphical plot is produced?

I have searched everywhere but failed to find any reference to this. I am working in linux.

Any help greatly appreciated.

Thanks

like image 382
user1218475 Avatar asked May 31 '13 18:05

user1218475


3 Answers

Only on Windows: try putting a bringToTop(-1) in your function:

z <- function() {
  plot(1:3)
  bringToTop(-1)
}
z()

It will temporarily steal focus but then return it.

Another strategy on Windows:

z <-  function(){
    windows(restoreConsole=TRUE)
    plot(1)
}
z()

I'm still thinking here...

like image 54
Thomas Avatar answered Nov 08 '22 19:11

Thomas


If you are more interested in doing something else while the plots are being produced then I would suggest opening a pdf device so that all the plots go to a pdf file in the background and do not interfere with whatever else you are doing. Then when you are ready to look through the plots you just open the pdf file and look at the plots (and you can easily go back to previous plots this way).

like image 2
Greg Snow Avatar answered Nov 08 '22 20:11

Greg Snow


If wmctrl is installed on your system, you can avoid losing focus by redefining the plot function like this:

plot <- function(...) {
  graphics::plot(...)
  system("wmctrl -a :ACTIVE:")
}

It seems to work quite well, in the fluxbox window manager at least. I tried different scenarios like switching to a different window during a long calculation before plot is called, and opening multiple plots.

Put it into your .Rprofile if you want it to persist.

like image 1
sieste Avatar answered Nov 08 '22 20:11

sieste