gregory_r_warnes@groton.pfizer.com
2003-Jul-07 19:50 UTC
[Rd] feature enhancement request & patch: dev.control(displaylist='en (PR#3424)
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_000_01C344B0.28BC0750
Content-Type: text/plain; charset="windows-1252"
Summary:
Currently R provides
> dev.control(displaylist='inhbit')
to turn *off* the recording of graphics operations in a device, but there is
no method to explicitly turn it on.
Attached is a patch which provides support for
> dev.control(displaylist='enable')
to explicitly turn on recording of graphics operations.
Background:
I'm using R in a non-interactive context and want to be able to use dev.copy
to copy the graph from one device to another so that I can create graphs in
a number of output formats without re-running the sequence of plot commands
(which include some expensive computations).
Unfortunately, this does not currently work for many graphics devices since
they have recording of graphics operations turned off by default, and there
is no way to turn it on. The attached patch provides a modified dev.control
and support functions to allow display recording to be turned on.
With the attached, the following text produces 3 copies of the original plot
in the 3 different output formats:
postscript(file="heatmap.eps", onefile=FALSE)
dev.control(displaylist='enable')
heatmap( matrix(rnorm(100),ncol=5))
dev.copy(bitmap,file="heatmap.png", res=100); dev.off()
dev.copy(pdf,file="heatmap.pdf", onefile=F); dev.off()
dev.off()
I've tested this patch on today's R-patched under Solaris 8 with
postscript(), pdf(), bitmap(), and x11() and it appears to work correctly.
As an aside, I wonder if it might be a good idea to change the parameter to
dev.control to make it more mnemonic and easier to use. For example, the
parameter could be 'record' and take a boolean argument instead of a
arbitrary string. Further, it would be convenient for my use if the
'record' parameter was an optional parameter for the device creation
commands. Thus one could do
postscript(file="heatmap.eps", onefile=FALSE, record=TRUE)
heatmap(...)
...
-Greg
<<dev_control.patch>>
LEGAL NOTICE
Unless expressly stated otherwise, this message is confidential and may be
privileged. It is intended for the addressee(s) only. Access to this E-mail by
anyone else is unauthorized. If you are not an addressee, any disclosure or
copying of the contents of this E-mail or any action taken (or not taken) in
reliance on it is unauthorized and may be unlawful. If you are not an addressee,
please inform the sender immediately.
------_=_NextPart_000_01C344B0.28BC0750
Content-Type: application/octet-stream;
name="dev_control.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="dev_control.patch"
diff -ur R-patched/src/library/base/R/device.R
R-patched-grw/src/library/base/R/device.R=0A---
R-patched/src/library/base/R/device.R 2002-05-28 06:45:11.000000000 -0400=0A+++
R-patched-grw/src/library/base/R/device.R 2003-07-07 12:00:33.000000000
-0400=0A@@ -180,9 +180,12 @@=0A {=0A if(!missing(displaylist)) {=0A
if(displaylist =3D=3D "inhibit") {=0A- if(dev.cur() > 1)
.Internal(dev.control())=0A+ if(dev.cur() > 1)
.Internal(dev.control(FALSE))=0A else stop("dev.control()
called without an open graphics device")=0A- } else stop("displaylist
should be inhibit")=0A+ } else if(displaylist =3D=3D "enable")
{=0A+ if(dev.cur() > 1) .Internal(dev.control(TRUE))=0A+
else stop("dev.control() called without an open graphics device")=0A+
} else stop("displaylist should be inhibit")=0A }=0A
invisible()=0A }=0Adiff -ur R-patched/src/library/base/man/dev2.Rd
R-patched-grw/src/library/base/man/dev2.Rd=0A---
R-patched/src/library/base/man/dev2.Rd 2002-05-28 06:45:12.000000000 -0400=0A+++
R-patched-grw/src/library/base/man/dev2.Rd 2003-07-07 12:00:18.000000000
-0400=0A@@ -17,8 +17,7 @@=0A For \code{dev.print}, this includes
\code{which} and by default any=0A \code{\link{postscript}} arguments.}=0A
\item{which}{A device number specifying the device to copy to}=0A-
\item{displaylist}{A character string: the only valid value is=0A-
\code{"inhibit"}.}=0A+ \item{displaylist}{A character string:
\code{"inhibit"} or \code{"enable"}.}=0A }=0A
\description{=0A \code{dev.copy} copies the graphics contents of the current
device=0A@@ -35,7 +34,8 @@=0A =0A \code{dev.control} allows the user to
control the recording of=0A graphics operations in a device. If
\code{displaylist} is \code{"inhibit"}=0A- then recording is turned
off.=0A+ then recording is turned off. If \code{displaylist} is
\code{"enable"} =0A+ recording is turned on.=0A }=0A \value{=0A
\code{dev.copy} returns the name and number of the device which has=0Adiff -ur
R-patched/src/main/graphics.c R-patched-grw/src/main/graphics.c=0A---
R-patched/src/main/graphics.c 2003-02-04 10:19:52.000000000 -0500=0A+++
R-patched-grw/src/main/graphics.c 2003-07-07 11:16:39.000000000 -0400=0A@@
-6121,3 +6121,12 @@=0A else=0A dd->displayListOn =3D FALSE;=0A
}=0A+=0A+void enableDisplayList(DevDesc *dd)=0A+{=0A+
GEinitDisplayList((GEDevDesc*) dd);=0A+ if (dd->newDevStruct)=0A+
((GEDevDesc*) dd)->dev->displayListOn =3D TRUE;=0A+ else=0A+
dd->displayListOn =3D TRUE;=0A+}=0Adiff -ur R-patched/src/main/names.c
R-patched-grw/src/main/names.c=0A--- R-patched/src/main/names.c 2003-03-22
21:13:18.000000000 -0500=0A+++ R-patched-grw/src/main/names.c 2003-07-07
11:48:45.000000000 -0400=0A@@ -716,7 +716,7 @@=0A =0A /* Graphics */=0A
=0A-{"dev.control", do_devcontrol, 0, 111, 0, {PP_FUNCALL, PREC_FN,
0}},=0A+{"dev.control", do_devcontrol, 0, 111, 1, {PP_FUNCALL,
PREC_FN, 0}},=0A {"dev.copy", do_devcopy, 0, 111, 1, {PP_FUNCALL,
PREC_FN, 0}},=0A {"dev.cur", do_devcur, 0, 111, 0, {PP_FUNCALL,
PREC_FN, 0}},=0A /*=0Adiff -ur R-patched/src/main/plot.c
R-patched-grw/src/main/plot.c=0A--- R-patched/src/main/plot.c 2003-02-25
18:08:41.000000000 -0500=0A+++ R-patched-grw/src/main/plot.c 2003-07-07
11:47:16.000000000 -0400=0A@@ -51,9 +51,13 @@=0A =0A SEXP do_devcontrol(SEXP
call, SEXP op, SEXP args, SEXP env)=0A {=0A+ int listFlag =3D
LOGICAL(CAR(args))[0];=0A checkArity(op, args);=0A-
inhibitDisplayList(CurrentDevice());=0A- return R_NilValue;=0A+
if(listFlag)=0A+ enableDisplayList(CurrentDevice());=0A+ else=0A+
inhibitDisplayList(CurrentDevice());=0A+ return ScalarLogical(listFlag);=0A
}=0A =0A SEXP do_devcopy(SEXP call, SEXP op, SEXP args, SEXP env)=0A
------_=_NextPart_000_01C344B0.28BC0750--
