From hb at biostat.ucsf.edu  Tue Sep 24 21:52:34 2013
From: hb at biostat.ucsf.edu (Henrik Bengtsson)
Date: Tue, 24 Sep 2013 12:52:34 -0700
Subject: [Rd] recordPlot() on non-interactive graphics device?
In-Reply-To: <CADwqtCOFhr1MedUgZFHKoL8Fo77Fqqum7ENCyEXEuJbvGsQknQ@mail.gmail.com>
References: <CAFDcVCT0P9kHiYkwvYCS03u7CEZd0kd7V00hhtb+-Otb1mVe_Q@mail.gmail.com>
	<CADwqtCNPm4txdYdngabr7WcsFNh7-O=oFPgCGhgFaEQUSLNEAQ@mail.gmail.com>
	<CADwqtCOFhr1MedUgZFHKoL8Fo77Fqqum7ENCyEXEuJbvGsQknQ@mail.gmail.com>
Message-ID: <CAFDcVCSk1WWh037ff9uLLVdFnryxELr6OEestZmE1-FRJ_Y4qQ@mail.gmail.com>

Thanks Gabriel.  It works - I did not know about dev.control() and its
help page clearly says that "Initially recording is on for screen
devices, and off for print devices".

I've submitted a patch (PR#15472) for adding a "see also" linking to
dev.control():

Bug 15472 - PATCH: Adding see also link for help("recordPlot",
package="grDevices")
https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=15472

/Henrik

On Tue, Sep 24, 2013 at 11:43 AM, Gabriel Becker <gmbecker at ucdavis.edu> wrote:
> To be a little less terse:
>
> I agree that notes/discussion about what recordPlot/replayPlot do when there
> is no display list and that non-interactive devices don't create a
> displaylist by default but can be instructed to do so via dev.control (at
> least some, I don't claim to have checked them all) would probably be
> helpful, as well as a see also link to dev.control.
>
> ~G
>
>
>
> On Tue, Sep 24, 2013 at 11:25 AM, Gabriel Becker <gmbecker at ucdavis.edu>
> wrote:
>>
>> Henrik,
>>
>> This works for me:
>>
>> > png("test.png")
>> > dev.control(displaylist="enable")
>> > plot(1:10)
>> > rp = recordPlot()
>> > dev.off()
>> X11cairo
>>        2
>> > rp
>>
>> HTH,
>> ~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 at 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 at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>>
>>
>>
>> --
>> Gabriel Becker
>> Graduate Student
>> Statistics Department
>> University of California, Davis
>
>
>
>
> --
> Gabriel Becker
> Graduate Student
> Statistics Department
> University of California, Davis



[Rd] recordPlot() on non-interactive graphics device?
Henrik Bengtsson