Re: [R] Files and classes in a package?

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri 23 Jul 2004 - 06:18:49 EST


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.@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} locale.

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@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

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Jul 23 06:25:41 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:55:11 EST