Undefined slot classes in definition?
Asked Answered
S

1

6

I am trying to build a package that contains own S4 class definitions. R check works but issues the following warning: undefined slot classes in definition mySecond.

I set to classes while one slot in the second class is of class myFirstClass. E.g.:

setClass("myFirst",representation(field_one = "character",
                                  field_two = "list")
         )

setClass("mySecond",representation(a = "character",
                                   b = "myFirst")
         )

Note:Though S4 might be easier to handle I'd like to stick to S4 here, because I am mapping information from a database and prefer S4's stricter definitions in this case. The compilation does work but I try to fulfill CRAN's standards here and want to get rid of the warnings. Btw: getClassDef gives reasonable result for both classes.

Selden answered 23/8, 2013 at 13:44 Comment(0)
S
9

Maybe your class definitions are in separate files, and the collation is such that mySecond is defined before myFirst? See the Collate: field in DESCRIPTION (Section 1.1.1 of RShowDoc("R-exts"), or follow one model of structuring packages where a file AllClasses.R contains class definitions.

Sebastiansebastiano answered 23/8, 2013 at 14:3 Comment(8)
Thanks for that RUtils function. Slick! Got my class definitions all in one file called classDefinitions.R. Feel like my problem might have to do with my lack of understanding this zzz.R file construction and the .First.Lib?Selden
.First.lib is now "defunct" in recent R (it was used when packages were not required to have a NAMESPACE; use .onLoad or .onAttach instead), but actually few packages need these hooks -- just define your classes in classDefintions.R such that myFirst is defined before mySecond.Sebastiansebastiano
Thx, did not know it was defunct. Really must have read some outdated stuff. Is there any read you'd recommend on creating packages with S4?Selden
Sorry, I don't really have anything special to recommend; Brobdingnag was an R package created for this purpose and I remember agreeing with it mostly at the time, but that was quite a while ago. Hadley (not sure why his classes represent data as inefficient 'rows', rather than vectors) ends his exposition with reference to package issues.Sebastiansebastiano
Is there any indication when I really need .onLoad?Selden
S4 per se does not require use of .onLoad; maybe you'd use it if you were, say, initializing a class instance from a web resource that you consulted when the package is loaded, or perhaps if you were building classes in some dynamic way. But these are not normal use cases, and not really related to S4.Sebastiansebastiano
> RShowDoc("R-exts") Error in RShowDoc("R-exts") : document not foundGlamour
@MatthaeusGaiusCaesar this should be a function that works very generally; how did you install R?Sebastiansebastiano

© 2022 - 2024 — McMap. All rights reserved.