Skip to content
Back to formatted view

Raw Message

Message-ID: <971536df0508251612551bd76a@mail.gmail.com>
Date: 2005-08-25T23:12:18Z
From: Gabor Grothendieck
Subject: S3 class question
In-Reply-To: <1253d67a05082516037aa8a2e0@mail.gmail.com>

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.