Search code examples
r

Inhibit focus stealing when launching a new graphics plot in 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


Solution

  • 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.