5

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

dickoa
  • 18,217
  • 3
  • 36
  • 50

2 Answers2

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.

John Colby
  • 22,169
  • 4
  • 57
  • 69
2

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.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • First of all i would like to thank's you (and Jeffrey Horner) for littler it's really useful and also easier to use than Rscript (i even do some system admin in my kubuntu with R now !!). You're right about external frame, so far I tried tkrplot, the new r qt interface (qtbase and qtpaint) and even gnuplot (through TeachingDemos) and also I finally find a way to keep my R graphics without using Sys.sleep (I use locator instead and right click to continue the script). I'll try to find a more elegant solution to problem. Thank's again – dickoa Oct 20 '11 at 19:25
  • Pleasure to be of help. If you have a succinct little demo involving maybe just tcltk and tkrplot, I'd be happy to add that to the package (and of course give you full credit etc). What you asked here is a relevant problem, and we should ship with a sample solution. – Dirk Eddelbuettel Oct 20 '11 at 20:21
  • Great idea, I'll be very happy to send you a piece of reproductible code or post it here when I'll finish this work. – dickoa Oct 22 '11 at 01:19