An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20050825/8416f643/attachment.pl
S3 class question
3 messages · Joel Bremson, Bert Gunter, Gabor Grothendieck
Have you defined matSummary() as a generic with UseMethod:
matSummary<-function(...)UseMethod('matSummary')
-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA
"The business of the statistician is to catalyze the scientific learning
process." - George E. P. Box
-----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Joel Bremson Sent: Thursday, August 25, 2005 4:03 PM To: r-help at stat.math.ethz.ch Subject: [R] S3 class question Hi, I have a class called "spss" containing prepared info from an SPSS file.
... class(ret) = "spss" return(ret)
The function that returns this defined in a file that I source into R. Also in that file is a function matSummary.spss. I think I ought to be able to call
matSummary(ret)
to run the function, but only
matSummary.spss(ret)
will work. What am I doing wrong here? This seems like a simple problem yet I've been able to find nothing in the archives about this. Joel -- Joel Bremson Graduate Student Institute for Transportation Studies - UC Davis http://etrans.blogspot.com [[alternative HTML version deleted]]
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
On 8/25/05, Joel Bremson <joel3000 at gmail.com> wrote:
Hi, I have a class called "spss" containing prepared info from an SPSS file.
... class(ret) = "spss" return(ret)
The function that returns this defined in a file that I source into R. Also in that file is a function matSummary.spss. I think I ought to be able to call
matSummary(ret)
to run the function, but only
matSummary.spss(ret)
will work. What am I doing wrong here? This seems like a simple problem yet I've been able to find nothing in the archives about this.
Methods have to have a corresponding generic to be called like that.
Assuming your method has a single argument called ret define this:
matSummary <- function(ret) UseMethod("matSummary")
When you call matSummary the UseMethod call will forward
it to the appropriate method depending on the class of the
first argument, ret.