我试图在一个脚本中使用r,它将充当一个简单的命令行绘图工具。也就是说,用户在csv文件中输入管道,然后得到一个绘图。我可以通过各种临时文件机器找到一个很好的显示图,但是我遇到了一个障碍。在用户关闭窗口之前,我不知道如何让r继续运行。
如果我策划并退出,情节立即消失。如果我绘制并使用某种无限循环,用户将无法关闭该绘图;他必须使用我不喜欢的中断退出。我看到有一个getgraphicsEvent函数,但它声称不支持该设备(x11)。无论如何,它似乎并不支持onclose事件,只支持onmousedown。
有什么解决办法吗?
编辑:感谢Dirk提供查看tk接口的建议。以下是我的测试代码:
require(tcltk)
library(tkrplot)
## function to display plot, called by tkrplot and embedded in a window
plotIt<-function(){ plot(x=1:10, y=1:10) }
## create top level window
tt<-tktoplevel()
## variable to wait on like a condition variable, to be set by event handler
done <- tclVar(0)
## bind to the window destroy event, set done variable when destroyed
tkbind(tt,"<Destroy>",function() tclvalue(done) <- 1)
## Have tkrplot embed the plot window, then realize it with tkgrid
tkgrid(tkrplot(tt,plotIt))
## wait until done is true
tkwait.variable(done)