matplot(... panel.first=..) fails <==> dealing with "..." (PR#267)

Peter Dalgaard BSA p.dalgaard@biostat.ku.dk
06 Sep 1999 14:25:30 +0200


maechler@stat.math.ethz.ch writes:

> Maybe, the following is not a bug in the strict sense,....
> 
> The following code shows what the effect :
> 
>   p1 <- function(...) plot.default(...)
>   p2 <- function(...) { n <- names(list(...)); plot.default(...) }
> 
>   par(mfrow=c(2,2))
>   p1(1:10, panel.first = grid(10,10)) # works okay (grid drawn)
>   p2(1:10, panel.first = grid(10,10)) # doesn't draw the grid
...
> The real questions behind are:
> 
> 1a) Why is "..." changed at the moment that I do  list(...)
> 1b) is this basic behavior desirable / changeable ....

That's a result of lazy evaluation. plot.default is really playing
with fire, the way it is currently written. list(...) will force
evaluation of the promises which in turn causes grid() to be called
too early. I don't think it is desirable to change this behavior
(well, Robert wants us to consider eager evaluation, but that would
cause the construction to stop working in all cases!)

> 2) How can one work around? 
>    {save "..." to something else, first? 
>     or explicitly save panel.first?}
> 

Neither of the above, because the object is to access "..." without forcing
evaluation of its contents. One can do things like

> p2
function (...) 
{
    n <- names(match.call(expand.dots = F)[["..."]])
    plot.default(...)
}

Or, one can modify plot.default to take panel.first as an
*unevaluated* expression (mode "call" or "expression"), and do an
explicit eval(panel.first). But then you'd have to do 

p2(1:10, panel.first = quote(grid(10,10))) # or expression( )

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._