From sdavis2 at mail.nih.gov  Thu Mar  1 12:18:11 2007
From: sdavis2 at mail.nih.gov (Sean Davis)
Date: Thu, 1 Mar 2007 06:18:11 -0500
Subject: [Rd] Same method for more than one class
In-Reply-To: <45E6AF4E.9050107@bfro.uni-lj.si>
References: <45E6AF4E.9050107@bfro.uni-lj.si>
Message-ID: <200703010618.11599.sdavis2@mail.nih.gov>

On Thursday 01 March 2007 05:47, Gregor Gorjanc wrote:
> Hi,
>
> when defining method (I used length bellow just for the simplicity) for
> myClass (S4 class) I use
>
> setMethod(f="length", signature(x="myClass"),
>           def=function(x) {
>             cat("works")
>           })
>
> If I have myClass1 and myClass2 and mentioned method, which is not the
> default one, applies to both classes I have to write two setMethod()
> statements. Would it be possible to use
>
> signature(x=c("myClass1", "myClass2"))

Could you do:

catFun <- function(x) {
  cat("Works")
}
setMethod(f="length", signature(x="myClass1"),def=catFun)
setMethod(f="length", signature(x="myClass2"),def=catFun)

Sean



[Rd] Same method for more than one class
Sean Davis