[R] Advice collating an R package

Duncan Murdoch murdoch.duncan at gmail.com
Wed Nov 11 17:09:25 CET 2015


On 11/11/2015 7:16 AM, Glenn Schultz wrote:
> Hi All,
> When collating a package - where does the file of constants go?
>
> I have an R package that defines 36 new classes and the AllClasses file is getting quite long.  I would like to re-organize the files the following way - which is also easier for my personal mental map of what is going on.
>
> #' @includes foo1.R foo2.R
> setClass
> setGeneric
> setMethod(initialize)
> constructor function
>
> I also have a file fooC.R which defines the constants like days.in.month etc.  So should every file be
> #' @includes fooC. R foo1.R foo2.R
> setClass
> setGeneric
> setMethod(initialize)
> constructor function
>

Scoping in R doesn't care about the order of declaration.  The times 
when collation order matters are when you need to use one object in the 
package to build another one.  (You should be thinking of the source 
files as executable scripts that create a collection of objects, not as 
declarations.)

So just make sure that if you use object A from your package when 
building object B, that the source to build A is executed first.  Most 
people do this by naming the files:  they'll be executed in C collation 
order by default.  (You can list the files in the Collate field of your 
DESCRIPTION file if you want a different order; see Writing R Extensions 
for details).

Duncan Murdoch



More information about the R-help mailing list