Skip to content

eval() bug in plot.formula() ?

2 messages · Martin Maechler, Peter Dalgaard

#
I don't have time now to investigate myself,
and I'm not feeling like deciding myself if the following is a bug:

  myplot <- function(dat, cex = 1.2, ...) {
      if(!is.data.frame(dat <- as.data.frame(dat)))
	  stop("`dat' must be a data.frame")
      if(any(is.na(match(c("x","y"), names(dat)))))
	  stop("`dat' must have a `x' and a `y' component")
      plot(y ~ x, data= dat, cex=cex, ...)
  }

  dd <- list(x= 1:12, y = sin((1:12)/10))
  myplot(dd)
  ## Error in eval(expr, envir, enclos) : ... used in an incorrect context

  myplot(dd, col = "red") ## Works fine

  myplot(dd, cex=1)
  ## Error in eval(expr, envir, enclos) : ... used in an incorrect context

------------
The above code works fine in R 0.90  but fails already in 1.0.0

I believe it *is* a bug

Martin Maechler <maechler@stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO D10	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Martin Maechler <maechler@stat.math.ethz.ch> writes:
Hmm, it comes from fixing a much worse bug (the one where pch and
friends didn't get subsetted), so it's not advisable to revert the
change.

The problematic construction is this:

{
    m <- match.call(expand.dots = FALSE)
    if (is.matrix(eval(m$data, parent.frame()))) 
        m$data <- as.data.frame(data)
    dots <- m$"..."
    dots <- lapply(dots, eval, data, parent.frame())

and the problem is that dots has ... as a component in some cases.
This looks more like a bug in match.call than in plot.formula, I think