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"? [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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
We use file names like AllClass.R # definition of classes AllGeneric.R # definition of generic functions (or perhaps AllClasses.R and AllGenerics.R for the fastidious). As you say, these are not guaranteed to be processed first but we tend to use lower case letters for our other .R file names. By the way, I notice that Robert Gentleman used wrappers like if (!isGeneric("logDet")) { setGeneric("logDet", function(object) standardGeneric("logDet"), "numeric") } in one of his packages in Bioconductor so as to avoid accidently redefining generics. I think that is a good idea. "Henrik Bengtsson" <hb at maths.lth.se> writes:> 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"? > > [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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-- Douglas Bates bates at stat.wisc.edu Statistics Department 608/262-2598 University of Wisconsin - Madison http://www.stat.wisc.edu/~bates/ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On 21 May 2002, Douglas Bates wrote:> We use file names like > > AllClass.R # definition of classes > AllGeneric.R # definition of generic functions > > (or perhaps AllClasses.R and AllGenerics.R for the fastidious). As > you say, these are not guaranteed to be processed first but we tend to > use lower case letters for our other .R file names.Unfortunately there are locales in which lower case comes before upper case, surprisingly. en_US is one (on Linux and Solaris at least). So I think starting with 0 is safer. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Tue, May 21, 2002 at 05:47:45PM +0100, ripley at stats.ox.ac.uk wrote:> On 21 May 2002, Douglas Bates wrote: > > > We use file names like > > > > AllClass.R # definition of classes > > AllGeneric.R # definition of generic functions > > > > (or perhaps AllClasses.R and AllGenerics.R for the fastidious). As > > you say, these are not guaranteed to be processed first but we tend to > > use lower case letters for our other .R file names. > > Unfortunately there are locales in which lower case comes before upper > case, surprisingly. en_US is one (on Linux and Solaris at least). So I > think starting with 0 is safer. > > -- > Brian D. Ripley, ripley at stats.ox.ac.uk > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ > University of Oxford, Tel: +44 1865 272861 (self) > 1 South Parks Road, +44 1865 272860 (secr) > Oxford OX1 3TG, UK Fax: +44 1865 272595 > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._Explicit calls to class definition files can be included in the function .First.lib (this way you have full control on the order of the declarations) (look at the files zzz.R in many of packages of bioconductor) Cheers, Laurent -- Laurent Gautier CBS, Building 208, DTU PhD. Student D-2800 Lyngby,Denmark tel: +45 45 25 24 85 http://www.cbs.dtu.dk/laurent -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._