For incremental changes, it's easy to catch them at the device layer.
Assuming implementing a custom graphics device is outside the scope, you
would need to do something like take a snapshot each time R becomes idle,
which would be a lot of overhead. So you might need your own device that
would print to stdout, with some prefix that hides it from the buffer. Not
completely infeasible.


On Mon, Nov 18, 2013 at 4:41 PM, Vitalie Spinu <spinuvit@gmail.com> wrote:

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

	[[alternative HTML version deleted]]

