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}}
As this happens in exactly the same way in 1.8.1 and 1.9.0, why are you blaming `recent changes in R 1.9.x'? I am baffled as to what you think is `recent'. On Tue, 25 May 2004, Warnes, Gregory R wrote:> > 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,It is, via graphics:::plot.formula.> 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() )Not a standard idiom for a generic with a formula method, and I think you really should be dispatching to the method here. [...] -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
In R-1.8.1, I could work around the problem because the plot.formula function is directly executable because it is exported from the graphics package: _ platform sparc-sun-solaris2.8 arch sparc os solaris2.8 system sparc, solaris2.8 status Patched major 1 minor 8.1 year 2004 month 02 day 05 language R> methods(plot)[1] plot.HoltWinters* plot.POSIXct plot.POSIXlt [4] plot.TukeyHSD plot.acf* plot.data.frame [7] plot.decomposed.ts* plot.default plot.dendrogram* [10] plot.density plot.factor plot.formula ^^^^^^^^^^^^ [13] plot.function plot.hclust* plot.histogram [16] plot.isoreg* plot.lm plot.mlm [19] plot.ppr* plot.prcomp* plot.princomp* [22] plot.profile.nls* plot.spec plot.spec.coherency [25] plot.spec.phase plot.stl* plot.table [28] plot.ts plot.tskernel* Non-visible functions are asterisked> plot.function > plot.functionfunction (x, from = 0, to = 1, xlim = NULL, ...) { if (!is.null(xlim)) { ... While in R-1.9.x the plot.formula function is not exported:> version_ platform sparc-sun-solaris2.8 arch sparc os solaris2.8 system sparc, solaris2.8 status major 1 minor 9.0 year 2004 month 04 day 12 language R> methods(plot)[1] plot.Date* plot.HoltWinters* plot.POSIXct* [4] plot.POSIXlt* plot.TukeyHSD plot.acf* [7] plot.data.frame* plot.decomposed.ts* plot.default [10] plot.dendrogram* plot.density plot.ecdf [13] plot.factor* plot.formula* plot.hclust* [16] plot.histogram* plot.isoreg* plot.lm [19] plot.medpolish* plot.mlm plot.ppr* [22] plot.prcomp* plot.princomp* plot.profile.nls* [25] plot.spec plot.spec.coherency plot.spec.phase [28] plot.stepfun plot.stl* plot.table* [31] plot.ts plot.tskernel* Non-visible functions are asterisked> plot.formulaError: Object "plot.formula" not found> -----Original Message----- > From: r-devel-bounces@stat.math.ethz.ch > [mailto:r-devel-bounces@stat.math.ethz.ch]On Behalf Of Prof > Brian Ripley > Sent: Tuesday, May 25, 2004 3:45 PM > To: Warnes, Gregory R > Cc: 'Troels Ring'; R-devel (E-mail) > Subject: Re: [Rd] problems with plot.formula > > > As this happens in exactly the same way in 1.8.1 and 1.9.0, > why are you > blaming `recent changes in R 1.9.x'? I am baffled as to what > you think is > `recent'. > > On Tue, 25 May 2004, Warnes, Gregory R wrote: > > > > > 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, > > It is, via graphics:::plot.formula.No, actually it is not:> graphics::plot.formulaError: 'plot.formula' is not an exported object from 'namespace:graphics'> > > 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() ) > > Not a standard idiom for a generic with a formula method, and > I think you > really should be dispatching to the method here. >The problem is that plot.formula is not exported, so I cannot dispatch directly to it. (This is what I did previously). -Greg> [...] > > -- > Brian D. Ripley, ripley@stats.ox.ac.uk > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ > University of Oxford, Tel: +44 1865 272861 (self) > 1 South Parks Road, +44 1865 272866 (PA) > Oxford OX1 3TG, UK Fax: +44 1865 272595 > > ______________________________________________ > R-devel@stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-devel >LEGAL NOTICE\ Unless expressly stated otherwise, this messag...{{dropped}}
Ahah, thanks Peter, I was not aware of the triple-colon operator ':::'. I think this will solve my specific problem. Still, the general issue of the argument name mismatch between R's (now well established) generics and methods, ie plot() and plot.formula(). Is anything going to be done about this? -Greg> -----Original Message----- > From: r-devel-bounces@stat.math.ethz.ch > [mailto:r-devel-bounces@stat.math.ethz.ch]On Behalf Of Peter Dalgaard > Sent: Wednesday, May 26, 2004 9:32 AM > To: Warnes, Gregory R > Cc: 'Prof Brian Ripley'; 'Troels Ring'; R-devel (E-mail) > Subject: Re: [Rd] problems with plot.formula > > > "Warnes, Gregory R" <gregory_r_warnes@groton.pfizer.com> writes: > > > > > This occurs because plot.formula is no longer directly > callable, > > > > > > It is, via graphics:::plot.formula. > > > > No, actually it is not: > > > > > graphics::plot.formula > > Error: 'plot.formula' is not an exported object from > 'namespace:graphics' > > Count'em, *three*! (The kosherness of using that operator is > debatable, but it'll do in a pinch...) > > -- > 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@stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-devel >LEGAL NOTICE\ Unless expressly stated otherwise, this messag...{{dropped}}