[R] S3 class question
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Aug 26 01:12:18 CEST 2005
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.
More information about the R-help
mailing list