[Rd] problems with plot.formula

Warnes, Gregory R gregory_r_warnes at groton.pfizer.com
Tue May 25 20:37:50 CEST 2004


With the recent changes in R 1.9.x, it is now impossible to properly call
plot on a formula() where the formula is provided via a named first
argument.  On today's R-1.9.1-alpha:

> x <- 1:10
> y <- rnorm(x,0.25)
> 
> plot(x~y)
> 
> plot(x=x~y)
Error in terms.formula(formula, data = data) : 
	argument is not a valid model
> 
> plot(formula=x~y)
Error in plot(formula = x ~ y) : Argument "x" is missing, with no default
> 

This occurs because plot.formula is no longer directly callable, and the
first argument to plot.formula() is 'formula' while the first argument to
plot() is 'x'.   Consequently one cannot properly pass a named first
argument since it will either fail for plot() or for plot.formula().  [I
suspect this is one reason why R CMD check complains about S3 methods that
don't match the call of the base method.]

This is much of a problem in interactive use, but it does cause problems in
functions, like my gregmisc::overplot(), which use the standard idiom

    m <- match.call()
    m[[1]] <- as.name('plot')
    eval(m, parent.frame() )

For the moment, I've had to resort to explicitly removing the name of the
first argument from the call:

    m <- match.call()
    m[[1]] <- as.name('plot')
    names(m)[2] <- ''
    eval(m, parent.frame() )

and since I have another function argument named f I also have to explicitly
mask that off

    m <- match.call()
    m[[1]] <- as.name('plot')
    names(m)[2] <- ''
    m$f <- NULL
    eval(m, parent.frame() )

What is going to happen with this problem of S3 method that don't match the
base signature?  Will these all the S3 methods be modified?  Or will some
sugar be introduced into the base method?  Or this this problem be
perennial, "so get used to it" ?

-Greg

Gregory R. Warnes
Manager, Non-Clinical Statistics
Pfizer Global Research and Development



LEGAL NOTICE\ Unless expressly stated otherwise, this messag...{{dropped}}



More information about the R-devel mailing list