[R] Files and classes in a package?

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jul 22 22:18:49 CEST 2004

Please do read the documentation, in this case the `Writing R Extensions 
Manual.  The para starting

An optional @samp{Collate} field (or OS-specific variants
@samp{Collate. at var{OStype}}, such as e.g.@: @samp{Collate.windows}) can
be used for controlling the collation order for the R code files in a
package when these are concatenated into a single file upon installation
from source.  The default is to try collating according to the @samp{C}

explains how to set the collation order.

On Thu, 22 Jul 2004, Shin, Daehyok wrote:

> While installing my small package, I met a tricky problem.
> For clarity, let me explain it with the following simplified example.
> In ~/pkg/R/aclass.R,
>     setClass("aclass", contains="bclass", representation(i="numeric"))
> In ~/pkg/R/bclass.R,
>     setClass("bclass", representation(j="numeric"))
> After building a "pkg" package, the file pkg.R in R directory has:
>     setClass("aclass", contains="bclass", representation(i="numeric"))
>     setClass("bclass", representation(j="numeric"))
> When combining the source files, R seems to generate one new source file
> based on alphabetic orders of file names. In this case, loading the "pkg"
> package failed with the following error message.
> > library(pkg)
> Error in methodsPackageMetaName("C", name) :
>         The name of the object (e.g,. a class or generic function) to find
> in the meta-data must be a single string (got an object of class "NULL")
> > traceback()
> 12: methodsPackageMetaName("C", name)
> 11: classMetaName(Class)
> 10: getClassDef(Class, where)
> 9: getClass(cl, TRUE)
> 8: .validDataPartClass(clDef, name)
> 7: reconcilePropertiesAndPrototype(name, slots, prototype, superClasses,
>        where)
> 6: makeClassRepresentation(Class, properties, superClasses, prototype,
>        package, validity, access, version, sealed, where = where)
> 5: setClass("aclass", contains = "bclass", representation(i = "numeric"))
> 4: eval(expr, envir, enclos)
> 3: eval(i, envir)
> 2: sys.source(codeFile, loadenv, keep.source = keep.source)
> 1: library(pkg)
> I suspect the reason is that class "bclass" is not defined when class
> "aclass" is defined. To maintain source files effectively, I don’t want to
> combine two files into one file or change their file names.
> Surely, there may be elegant solutions for this somewhat trivial issue. But,
> I can’t find it. Can you help me? Thanks.
> Daehyok Shin

> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list