Re: [R] S3 class question

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Fri 26 Aug 2005 - 09:12:18 EST

On 8/25/05, Joel Bremson <joel3000@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.



R-help@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 Received on Fri Aug 26 09:16:42 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:56 EST