[ESS] Graphics in emacs window: how to copy R screen devices in non-interactive sessions (remotes)

Vitalie Spinu spinuvit at gmail.com
Tue Nov 19 01:41:42 CET 2013

 >>> Michael Lawrence on Mon, 18 Nov 2013 16:07:22 -0800 wrote:

 ML> To make dev.copy work with off-screen devices, you need to call dev.control
 ML> ("enable"). 

 ML> So you could plot to a temporary file, then take snapshots to another file like
 ML> this:
 ML> pdf("test1.pdf")
 ML> dev.control(displaylist = "enable")
 ML> plot(1:10)
 ML> dev.copy(pdf, "test2.pdf")
 ML> dev.off()
 ML> # should now have a valid test2.pdf
 ML> dev.off() # finished

Thanks. This indeed worked, but only for png device. With pdf it produce
completely black images for me.

    ## pdf("main.pdf")
    dev.control(displaylist = "enable")
    dev.copy(png, "test1.png")
    abline(h = 5)
    dev.copy(png, "test2.png")

Now the next problem. It doesn't seem to work with plot.new hook. 
   ## options(device = mypng)
   dev_mirror <- function(){
       dev.control(displaylist = "enable")
       dev.copy(png, "current.png")
   setHook("plot.new", NULL, "replace")
   setHook("plot.new", dev_mirror, "replace")
   plot(1:5); abline(h = 3)

 ML> But I wonder how Emacs will see the file in the remote case? Maybe you could
 ML> somehow have R print the contents of the file, but hide it from the buffer?

Either this way, or fetching the file from the remote with tramp. In my
experience the first option is much faster, but for now I would be happy
with either.


More information about the ESS-help mailing list