[R] Best way to setClass and setMethod for an R package?

Martin Morgan mtmorgan at fhcrc.org
Sun Aug 21 17:33:16 CEST 2011


On 08/21/2011 05:56 AM, Uwe Ligges wrote:
>
>
> On 21.08.2011 00:48, Jonathan Greenberg wrote:
>> Folks:
>>
>> I'm putting together an R package, and I was wondering where,
>> specifically, I put both class definitions (via setClass) as well as
>> setMethod calls? Is there a particular file name I need to use?

Hi Jonathan

In principle, S4 methods can dispatch on multiple classes, and an 
approach has been to have files AllClasses.R and AllGenerics.R to 
implement class and generic definitions, then foo-methods.R for methods 
defined on the generic foo. An 'advantage', for the lazy amongst us, is 
that this usually leads to a collation order that is appropriate -- 
class definition before use in method dispatch -- so that the Collates: 
field in the DESCRIPTION file does not have to be maintained.

In practice many S4 generics dispatch on a single argument and while 
there might be the equivalent of AllGenerics.R, the classes and their 
associated methods are defined in MyClass-methods.R.

Martin

>
> No, any file name, e.g.
> .../name_of_your_package/R/Name_of_your_class.R
>
>
> Uwe Ligges
>
>
>
>> Thanks!
>>
>> --j
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


-- 
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109

Location: M1-B861
Telephone: 206 667-2793



More information about the R-help mailing list