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? There are several reasons why I DO NOT want to define assayObjectDemo in the same package as assayObject, but I am not sure what the issue is here. If I step through the code in an ESS R session it works fine. Thanks in advance, Ramiro ________________________________________ From: Rolf Turner [r.turner at auckland.ac.nz] Sent: Monday, February 23, 2015 3:41 PM To: Ramiro Barrantes; r-help at r-project.org Subject: Re: [R] Not finding superclass in library On 24/02/15 09:35, Ramiro Barrantes wrote:> Hello, > > I have a library that I created .....<SNIP> No you ***DO NOT***. You have a ***PACKAGE***. If you cannot even get your terminology straight, what hope is there for you? cheers, Rolf Turner -- Rolf Turner Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276 Home phone: +64-9-480-4619
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
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