External graphical device for littler or Rscript

邮差的信 提交于 2019-12-12 11:07:25

问题


I really like littler is really great for scripting using R. But i don't how to use external graphics device a la gnuplot (for example using Octave). I'm able to produce the desired graph but i have to use Sys.sleep and i don't want to do so, because i want to close it my self in an interactive way or better continue the script without closing the device.

So far this is what my code looks like :

#!/usr/bin/env r -t


suppressMessages(require(Cairo))

CairoX11()
plot(rnorm(1000), pch = 19)
Sys.sleep(50)

# some code without closing the graphics window

My question is : Do you know a way to achieve that ?

Any hint, document, link or code will be appreciated


回答1:


Besides John's suggestion, you could be explicit and invoke one of the GUI packages to bring up a new 'frame' (or 'window') that then shows the plot. That will remain on-screen until the user (or an external event) terminates that window.

The tcltk package can be used along with the tkrplot package; this is the most portable. RGtk2 is more modern but harder to install / use on Windows as Gtk2 is not exactly native there. There is more---search for R GUIs here and on other places on the intertubes.




回答2:


I don't know of a way to do that, since these are purposely non-interactive ways of running R. I would just run your script in an interactive R session with par(ask=T). That way it'll pause for the user between figures, like the demos in the R documentation.



来源:https://stackoverflow.com/questions/7835947/external-graphical-device-for-littler-or-rscript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!