From jmc@research.bell-labs.com  Mon Jan 20 02:14:03 2003
From: jmc@research.bell-labs.com (John Chambers)
Date: Mon Jan 20 02:14:03 2003
Subject: [Rd] Methods package is now attached by default
References: <3E287D10.8692826A@research.bell-labs.com>
 <Pine.WNT.4.44.0301181044480.1088-100000@petrel> <15915.7358.236309.327617@mithrandir.hornik.net>
Message-ID: <3E2B4CFB.31C0E55F@research.bell-labs.com>

I implemented the change in usemethods that Brian and I discussed, but
was waiting to commit it to give people a chance to protest.  The change
passes "make fullcheck"  and may avoid some of the conflicts, perhaps
the three packages you mentioned.

If no one objects, I'll commit the modification tomorrow am, New York
time.

John

Kurt Hornik wrote:
> 
> >>>>> Prof Brian D Ripley writes:
> 
> > On Fri, 17 Jan 2003, John Chambers wrote:
> >> There are two main known differences from having methods attached:
> >>
> >> - the definition of class() changes, in particular no object ever has a
> >> NULL class.  If you have code that depends on test such as
> >> `if(is.null(class(x)))...', there may be problems.
> >>
> >> Usually code with those sort of tests is doing a workaround of the fact
> >> that not all objects had a class before.  The best solution is usually
> >> to ask what the code really wants to do.  If you do have to retain
> >> exactly the old behavior, one solution is to copy the version of class
> >> and class<- from the base package and use those (as baseClass and
> >> baseClass<-, e.g.) instead of class and class<-).
> 
> > Here is one example, which makes the MASS scripts fail.
> 
> >> library(MASS)
> >> corresp
> > function (x, ...)
> > {
> >     if (is.null(class(x)))
> >         class(x) <- data.class(x)
> >     UseMethod("corresp", x, ...)
> > }
> 
> > That used to work with matrices, and dispatch to corresp.matrix.  Now
> > a matrix has reported class "matrix" but dispatch occurs to
> > corresp.default.  The temporary fix is to remove the is.null
> > condition.
> 
> > That's quite a common construction, and I think I should expect
> > UseMethod to dispatch on the class class() reports.  So it looks to me
> > as if UseMethod needs to be altered to do so.
> 
> > ...
> 
> The daily check process on all CRAN packages shows that the packages
> 
>         StatDataML geoR ipred xtable
> 
> now fail running their examples with methods loaded by default.  The
> three latter can be traced immediately to variations on the above; the
> first fails in
> 
>     if (is.factor(x)) {
>       attr(xtmp, "levels") <- NULL
>       class(xtmp) <- class(xtmp)[!class(xtmp) %in% c("ordered","factor")]
>     }
> 
> with the error message
> 
> Error in "class<-"(*tmp*,
>                    value = class(xtmp)[!class(xtmp) %in% c("ordered",  :
>         Invalid replacement object to be a class string
> 
> I think I can tell David how to fix this, but wasn't quite sure about
> the wording in the error message ...
> 
> I assume I should wait before contacting the authors of the other 3
> packages for changing their code---or do we already have an official
> recommendation?
> 
> -k
> 
> ______________________________________________
> R-devel@stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-devel

-- 
John M. Chambers                  jmc@bell-labs.com
Bell Labs, Lucent Technologies    office: (908)582-2681
700 Mountain Avenue, Room 2C-282  fax:    (908)582-3340
Murray Hill, NJ  07974            web: http://www.cs.bell-labs.com/~jmc



[Rd] Methods package is now attached by default
John Chambers