[R] setClass() and packages

David James dj at research.bell-labs.com
Tue May 21 13:44:08 CEST 2002


Hello,

Henrik Bengtsson wrote:
> Where should the setClass() ('methods' package) calls be placed in a
> package? I try to follow a one-class-one-file principe, but since
> setClass("ClassA", "ClassB") has to come a after setClass("ClassB", [snip])
> it is not possible to fully follow this rule. So the best I can do now is to
> put all setClass() calls in a file named "000.R" (I know this file is *not*
> guaranteed to be included first, but it works with current build script):
> 
>   setClass("ClassB", [snip])
>   setClass("ClassA", "ClassB")
>   ...
> 
> Doing like this is fine with me, but is this the correct/best way? How are
> other people dealing with this "problem"?

I'm not sure there's a "coding standard" in this area.  I've found
that splitting the code into a main (or "public") file and
into support/utility files has worked well for me.  The main
file defines the interface through setClass, setGeneric, etc.,
and the code for the actual implementation (mostly independent of
version 4 style classes) resides in the support/utilities files.
A makefile generally concatenates these files in the right order
into one big file for installation.

Admittedly, this setup is biased for compatibility between old-
and new-style classes and methods: new-style classes and methods
are used to define the public interfaces to the package, while
existing functions (with names like print.classFoo) are delegated
(relegated?:-) to the implementation.

Regards,

--
David

> 
> [R v 1.5.0 2002-04-29 on WinMe]
> 
> Thanks
> 
> Henrik Bengtsson
> 
> Dept. of Mathematical Statistics @ Centre for Mathematical Sciences
> Lund Institute of Technology/Lund University, Sweden (+2h UTC)
> Office: P316, +46 46 222 9611 (phone), +46 46 222 4623 (fax)
> h b @ m a t h s . l t h . s e, http://www.maths.lth.se/bioinformatics/
> 
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

-- 
David A. James
Statistics Research, Room 2C-253            Phone:  (908) 582-3082       
Bell Labs, Lucent Technologies              Fax:    (908) 582-3340
Murray Hill, NJ 09794-0636
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list