[R] Not finding superclass in library
Ramiro Barrantes
ramiro at precisionbioassay.com
Tue Feb 24 17:34:13 CET 2015
Thank you so much for your help. Will aim at making a reproducible example next time, maybe if I had done that I would realized that the issue was that I was using Rscript, which does not load the methods library, which was the source of the problem.
________________________________________
From: Charles C. Berry [ccberry at ucsd.edu]
Sent: Monday, February 23, 2015 10:20 PM
To: Ramiro Barrantes
Cc: Rolf Turner; r-help at r-project.org
Subject: Re: Not finding superclass in library
On Mon, 23 Feb 2015, Ramiro Barrantes wrote:
> Thank you for pointing this out. I had no idea about the distinction
> but there are some good references on the matter
> (http://www.r-bloggers.com/packages-v-libraries-in-r/). I am pasting
> the corrected version below, any suggestions appreciated:
>
> I have a package that I created that defines a parent class,
> assayObject.
>
> I created other classes that inherit from it, say assayObjectDemo.
> Each one of those classes I wanted to make in its own directory separate
> from where the assayObject is defined (there are reasons for that).
>
> But now if I do:
>
> library(assayObject) #<--- where parent object is defined
> source("assayObjectDemo.R")
>
> where assayObjectDemo.R is just:
>
> setClass("assayObjectDemo",contains="assayObject")
> createDemoAssayObject <- function() {
> df <- data.frame()
> assay<-new(Class="assayObjectDemo")
> assay
> }
>
> I get:
>
> Error in reconcilePropertiesAndPrototype(name, slots, prototype, superClasses, :
> no definition was found for superclass “assayObject” in the specification of class “assayObjectDemo”
>
> What can I do?
Start with a reproducible example. Here is one:
library(Matrix)
tmpf <- tempfile(fileext=".R")
cat('setClass("MatrixDemo",contains="Matrix")',file=tmpf)
source(tmpf)
slotNames("MatrixDemo")
And it produces the expected output without error:
[1] "Dim" "Dimnames"
Since this works fine for a widely used package and fails for your
(unspecified) package, I suspect there is a problem with your package.
If I had to guess, I'd say it is a NAMESPACE issue. Be sure your
exportClasses directive is correctly formed per Section 1.5.6
"Namespaces with S4 classes and methods" of R-exts.
r-devel might be a better venue for this discussion.
HTH,
Chuck
More information about the R-help
mailing list