[R] Ellipsis arguments for plot.formula

Amit Ganatra amit_d_ganatra at yahoo.com
Thu Jul 10 20:51:22 CEST 2008


Hi:
I have a function as follows:
 my.plot    <- function( x, y = NULL, ... )
{
  plot( x, y, cex.axis=0.5, ...)
}

Set up the variables:
x <- 1:10; y <- x; tdf <- data.frame( x, y ); main.str <- "test"

I will exercise the function in two ways:

> my.plot( y ~ x, tdf, main = "test" )
This works fine

> my.plot( y ~ x, tdf, main = main.str )
Error in eval(expr, envir, enclos) : 
  ..1 used in an incorrect context, no ... to look in

Turns out that plot.formula is looking for the name "main.str" in its parent frame. If I define the name main.str in my.plot the function works fine.

Is this a bug?
I have a clunky workaround where I get the parent.frame in my.plot and create the variables in my.plot, but I don't like the solution. 

Thanks



More information about the R-help mailing list