[R] Files and classes in a package?

From: Shin, Daehyok <sdhyok_at_email.unc.edu>
Date: Fri 23 Jul 2004 - 06:07:47 EST


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



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:14:29 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 02:37:30 EST