[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.


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


Now the next problem. It doesn't seem to work with plot.new hook. 
   
   ## options(device = mypng)
   dev_mirror <- function(){
       cat("here\n")
       dev.control(displaylist = "enable")
       dev.copy(png, "current.png")
       dev.off()
   }
   
   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.

    Vitalie



More information about the ESS-help mailing list