On Mon, Mar 17, 2014 at 4:08 AM, David Winsemius <dwinsem...@comcast.net>wrote:

> S3 classes only dispatch on the basis of the first parameter class.


A minor distinction: S3 classes only dispatch on the basis on *one* of the
parameters. The person who writes the generic gets to choose, and for
predict() it is the first parameter, but it doesn't have to be for other
generics.

In model-fitting functions you often have formula= as the first argument
and data= as the second, and it makes much more sense to dispatch on data=
than on formula=.

The first well-known example is probably MASS::loglm, used in "S
Programming" to illustrate this issue but most of the methods in my survey
package also dispatch based on the second argument.




> That was one of the reasons for the development of S4-classed objects. You
> say you have the expectation that the object is of a class that has an
> ordinary `predict` method presumably S3 in character,  so you probably need
> to write a function that will mask the existing method.



Or write an S4 method for predict and use setGeneric(). That's also not
perfect: if everyone did it there would be lots of competing S4 generics
with the same name, and too many people would have to understand how they
are scoped.



   -thomas


-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to