ripley@stats.ox.ac.uk
2000-Feb-25 14:35 UTC
[Rd] bug and fix : using panel.first with plot() in do.call() (PR#458)
On Fri, 25 Feb 2000 c.farrow@compserv.gla.ac.uk wrote:> 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.Yes, and a solution is do.call("plot", list(x=1:5, panel.first=quote(grid(2,2)))) as when you do this sort of thing you can't rely on lazy evaluation. replacing `quote' by `delay' will also work. The help page says they should be unevaluated expressions.> 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 > }Um, ?plot.default say panel.first and panel.last should be *expressions* *to be evaluated*, so is this not working as documented? -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._