Here is the source code for getGraphicsEvent:
function (prompt = "Waiting for input", onMouseDown = NULL, onMouseMove = NULL,
onMouseUp = NULL, onKeybd = NULL, consolePrompt = prompt)
{
if (!interactive())
return(NULL)
if (!missing(prompt) || !missing(onMouseDown) || !missing(onMouseMove) ||
!missing(onMouseUp) || !missing(onKeybd)) {
setGraphicsEventHandlers(prompt = prompt, onMouseDown = onMouseDown,
onMouseMove = onMouseMove, onMouseUp = onMouseUp,
onKeybd = onKeybd)
}
.External2(C_getGraphicsEvent, consolePrompt)
}
You can see why it returns NULL, since that's made explicit with if (!interactive()) return(NULL)
. Try this inserted into your original code:
getGraphicsEvent2 = function (prompt = "Waiting for input", onMouseDown = NULL, onMouseMove = NULL,
onMouseUp = NULL, onKeybd = NULL, consolePrompt = prompt)
{
# if (!interactive())
# return(NULL)
if (!missing(prompt) || !missing(onMouseDown) || !missing(onMouseMove) ||
!missing(onMouseUp) || !missing(onKeybd)) {
setGraphicsEventHandlers(prompt = prompt, onMouseDown = onMouseDown,
onMouseMove = onMouseMove, onMouseUp = onMouseUp,
onKeybd = onKeybd)
}
.External2(C_getGraphicsEvent, consolePrompt)
}
environment(getGraphicsEvent2) = environment(grDevices::getGraphicsEvent)
dragplot(rnorm(1000), rnorm(1000))
kbd = function(key) {
if (key == "q") { "Quit" } else NULL }
getGraphicsEvent2("Waiting for input", onKeybd = kbd)
It seems to lose functionality (i.e. I couldn't manipulate the plot on OSX with X11 as graphics device), but at least the plot stays up. The call to internal code for this function changed recently (to confirm, look at source code for R in two versions - the code for this function in R 2.6.2, for example is at R-2.6.2/src/library/grDevices/R/gevents.R).
?getGraphicsEvent
works for me inRterm.exe
. – Loveinidleness