Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

External graphical device for littler or Rscript

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

like image 500
dickoa Avatar asked Oct 09 '22 17:10

dickoa


2 Answers

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.

like image 193
Dirk Eddelbuettel Avatar answered Oct 13 '22 11:10

Dirk Eddelbuettel


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.

like image 22
John Colby Avatar answered Oct 13 '22 11:10

John Colby