Henrik Bengtsson
2013-Sep-24 18:14 UTC
[Rd] recordPlot() on non-interactive graphics device?
Hi. Q. Is there a way to record a plot using grDevices::recordPlot() without opening an interactive (=visible GUI window) graphics device (not even for a flash of a second)? Related: help("recordPlot", package="grDevices") says: "These functions record and replay the displaylist of the current graphics device." Is the intention that recordPlot() should be able to record from _any type_ of graphics device, or only for _interactive_ ones? For instance, windows(); plot(1:10); g <- recordPlot(); dev.off(); x11(); plot(1:10); g <- recordPlot(); dev.off(); Cairo::CairoWin(); plot(1:10); g <- recordPlot(); dev.off(); all produce 'recordplot' objects that replot the figure with replayPlot(g), whereas for instance png("foo.png"); plot(1:10); g <- recordPlot(); dev.off(); pdf("foo.pdf"); plot(1:10); g <- recordPlot(); dev.off(); produce "empty" replayPlot(g) outputs. Q. It it just a coincident that it appear that recordPlot()/replayPlot() only works for grDevices::deviceIsInteractive() graphics devices? If not, should ?recordPlot clarify that "These functions record and replay the displaylist of the current [interactive] graphics device."? Q. ...or is just the fact that currently png(), pdf() etc. won't populate "the displaylist" (whatever that is), but if they would, then recordPlot()/replayPlot() would indeed generate an non-empty plot? If so, a note like "Note, recordPlot() will often record an empty plot on non-interactive graphics devices as they do not populate the displaylist." may be add to the help. Thanks, Henrik
Gabriel Becker
2013-Sep-24 18:25 UTC
[Rd] recordPlot() on non-interactive graphics device?
Henrik, This works for me:> png("test.png") > dev.control(displaylist="enable") > plot(1:10) > rp = recordPlot() > dev.off()X11cairo 2> rpHTH, ~G sessionInfo(): R version 3.0.1 (2013-05-16) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_3.0.1 On Tue, Sep 24, 2013 at 11:14 AM, Henrik Bengtsson <hb@biostat.ucsf.edu>wrote:> Hi. > > Q. Is there a way to record a plot using grDevices::recordPlot() > without opening an interactive (=visible GUI window) graphics device > (not even for a flash of a second)? > > > Related: help("recordPlot", package="grDevices") says: > > "These functions record and replay the displaylist of the current > graphics device." > > Is the intention that recordPlot() should be able to record from _any > type_ of graphics device, or only for _interactive_ ones? For > instance, > > windows(); plot(1:10); g <- recordPlot(); dev.off(); > x11(); plot(1:10); g <- recordPlot(); dev.off(); > Cairo::CairoWin(); plot(1:10); g <- recordPlot(); dev.off(); > > all produce 'recordplot' objects that replot the figure with > replayPlot(g), whereas for instance > > png("foo.png"); plot(1:10); g <- recordPlot(); dev.off(); > pdf("foo.pdf"); plot(1:10); g <- recordPlot(); dev.off(); > > produce "empty" replayPlot(g) outputs. > > Q. It it just a coincident that it appear that > recordPlot()/replayPlot() only works for > grDevices::deviceIsInteractive() graphics devices? If not, should > ?recordPlot clarify that "These functions record and replay the > displaylist of the current [interactive] graphics device."? > > Q. ...or is just the fact that currently png(), pdf() etc. won't > populate "the displaylist" (whatever that is), but if they would, then > recordPlot()/replayPlot() would indeed generate an non-empty plot? If > so, a note like "Note, recordPlot() will often record an empty plot on > non-interactive graphics devices as they do not populate the > displaylist." may be add to the help. > > > Thanks, > > Henrik > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Gabriel Becker Graduate Student Statistics Department University of California, Davis [[alternative HTML version deleted]]
Seemingly Similar Threads
- recordPlot/replayPlot not working with saveRDS/readRDS
- [FORGED] recordPlot/replayPlot not working with saveRDS/readRDS
- recordPlot usage: add snaps to a list.
- [FORGED] recordPlot/replayPlot not working with saveRDS/readRDS
- recordPlot in 1.5.x, replayPlot in 1.6.0 problem