[R] why-s of method dispatching

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Mar 18 22:44:38 CET 2004


On Thu, 18 Mar 2004, Vadim Ogranovich wrote:

> I see. Thank you very much! 
> 
> Does R-Core have any plan to promote data.frame to an S4 class? In
> general, is there any "road-map" (formal or informal) for phasing out S3
> classes?

No, no.  There is a vast amount of existing code depending on S3 classes.
As you will see from Rolf Turner's reaction, many users wish to keep it 
that way.

BTW, not all of us would see it as promotion, as S3 and S4 classes have
different strengths.  It is unfortunate that the particular way S4 classes 
are implemented at present that they get confused with S3 classes.


> 
> Thanks,
> Vadim
> 
> > -----Original Message-----
> > From: Prof Brian Ripley [mailto:ripley at stats.ox.ac.uk] 
> > Sent: Thursday, March 18, 2004 12:24 AM
> > To: Vadim Ogranovich
> > Cc: R Help List
> > Subject: Re: [R] why-s of method dispatching
> > 
> > 
> > On Wed, 17 Mar 2004, Vadim Ogranovich wrote:
> > 
> > > I am having a problem to understand why as.data.frame 
> > method doesn't 
> > > dispatch properly on my class:
> > > 
> > > > setClass("Foo", "character")
> > > [1] "Foo"
> > > > as.data.frame(list(foo=new("Foo", .Data="a")))
> > > Error in as.data.frame.default(x[[i]], optional = TRUE) :
> > >  can't coerce Foo into a data.frame
> > > 
> > > I was expecting that this would call as.data.frame.character.
> > 
> > You have set an S4 class and as.data.frame is an S3 generic.
> > 
> > > list(foo=new("Foo", .Data="a"))
> > $foo
> > An object of class "Foo"
> > [1] "a"
> > 
> > and what as.data.frame sees is
> > 
> > > attributes(list(foo=new("Foo", .Data="a"))$foo)
> > $class
> > [1] "Foo"
> > attr(,"package")
> > [1] ".GlobalEnv"
> > 
> > so thinks this is an S3 class it knows nothing about.
> > 
> > > Another puzzle. If I explicitly call as.data.frame.character() it 
> > > would fail but for a different reason:
> > > 
> > > > as.data.frame.character(list(foo=new("Foo", .Data="a")))
> > > Error in unique.default(x) : unique() applies only to vectors
> > > 
> > > I was under an impression that an instance of "Foo" would 
> > be welcome 
> > > anywhere a "character" was, but it seems to be more subtle. 
> > What am I 
> > > missing?
> > 
> > The difference between S3 and S4 classes.
> > 
> > -- 
> > Brian D. Ripley,                  ripley at 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-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 
> 

-- 
Brian D. Ripley,                  ripley at 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




More information about the R-help mailing list