[Rd] bug and fix : using panel.first with plot() in do.call() (PR#457)

c.farrow@compserv.gla.ac.uk c.farrow@compserv.gla.ac.uk
Fri, 25 Feb 2000 15:19:43 +0100 (MET)


The following works as expected
        plot(1:5, panel.first=grid(2,2))
and if
        my.panel<-function() grid(2,2)
then
        plot(1:5, panel.first=my.panel() )
is also OK

but, 
        do.call("plot", list(x=1:5, panel.first=grid(2,2))
        do.call("plot", list(x=1:5, panel.first=my.panel)) 
        do.plot("plot", list(x=1:5, panel.first=my.panel() ))
do not draw the grid because the panel.first expression is evaluated
before the plot gets drawn.


A solution is to modify plot.default such that the line

panel.first
is replaced by

if(is.function(panel.first)) {
        panel.first()
}else {
        panel.first
}
This allows the previous behaviour, but also allows a function name to
be passed to plot using do.call()
now all the following produce the expected graph
plot(1:5, panel.first=grid(2,2))
plot(1:5, panel.first=my.panel())
plot(1:5,panel.first=my.panel)

do.call("plot", list(x=1:5, panel.first=my.panel ))

Similarly the line 

panel.last 
should be replaced by 
if(is.function(panel.last)) {
        panel.last()
} else {
panel.last
}

As far as I am aware this affects all recent versions.
Cheers, Colin.


-- 
Colin Farrow
Computing Service, University of Glasgow, Glasgow G12 8QQ
Tel: 0141 330 4862, c.farrow@compserv.gla.ac.uk

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._