From gregory_r_warnes at groton.pfizer.com  Tue May 25 20:37:50 2004
From: gregory_r_warnes at groton.pfizer.com (Warnes, Gregory R)
Date: Tue May 25 20:38:06 2004
Subject: [Rd] problems with plot.formula
Message-ID: <D7A3CFD7825BD6119B880002A58F06C20C521411@groexmb02.pfizer.com>


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}}


[Rd] problems with plot.formula
Warnes, Gregory R