Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getGraphicsEvent for reading the key board for a noninteractive session

In older versions of R, version 2.9 anyway, I was able to run an R program from batch using rterm.exe and create a graphics window that a user could scroll back and forth and view the graphs. I was able to do that by using some R code like:

 kbd <- function(key) { 
 if (key == "q") { "Quit" } else NULL } 
 getGraphicsEvent(" ",  onKeybd = kbd) 

This held the graphics viewer open until the user pressed the "q" key. In newer versions of R, it seems that since this is started from batch (non-interactive using Rterm.exe), the key value is always NULL and the graphics window simply flashes and closes. My question is if there is any way I can somehow convince the R system that I'm running a quasi-interactive session and get the behavior of getGraphicsEvent to not return NULL immediately?

like image 441
Phil Rack Avatar asked Aug 13 '11 23:08

Phil Rack


1 Answers

You can fake an interactive session in one that would be detected as non-interactive by starting Rterm with the option

--ess

on Windows, or

--interactive

on Unix-alikes.

This may cause other problems, because all functions will see the session as interactive. You can't change that flag in the middle of a session, since it affects lots of things related to I/O.

like image 120
user2554330 Avatar answered Oct 16 '22 19:10

user2554330