search for: setclass

Displaying 20 results from an estimated 651 matches for "setclass".

2020 Oct 05
2
S4 - inheritance changed by order of setClassUnion and setAs()
...ree of inheritance changes. This is my baseline example that defines the classes "grandma", "mother", "daughter" and a virtual class "mr_x". For a new instance if "daughter", "mr_x" is betweeen "mother" and "grandma". setClass("grandma", slots = c(a = "character")) setClass("mother", slots = c(b = "matrix"), contains = "grandma") setClass("daughter", slots = c(c = "list"), contains = "mother") setClassUnion(name = "mr_x", members =...
2010 Feb 02
1
S4 setClass / initialize misunderstanding
Hi, I recently ran into this problem. I couldn't find any mention of it in the setClass documentation. setClass("Foo", representation(file = "character")) setMethod("initialize", "Foo", function(.Object, file) { print(file) }) setClass("Bar", contains = "Foo") And the error: Error in print(file) : argument "file&quo...
2002 May 21
4
setClass() and packages
Where should the setClass() ('methods' package) calls be placed in a package? I try to follow a one-class-one-file principe, but since setClass("ClassA", "ClassB") has to come a after setClass("ClassB", [snip]) it is not possible to fully follow this rule. So the best I can do now is to...
2009 May 13
1
question about setClass
Hi R People: I have a question about setClass please. I'm working thru "R Programming for Bioinformatics". Actually, I was wondering if there is such a thing as an updateClass, in order to change a "contains" option, please? that is, if I had setClass("dog", representation(name="character",paws=&...
2020 Oct 06
0
S4 - inheritance changed by order of setClassUnion and setAs()
Andreas, As far as I can tell (/conjecture), this is because the list of classes a particular class inherits from directly is appended to as needed, and so the order that a class extends others isd refined by the order that those connections are defined. We can see this with two setClassUnion calls, rather than required setAs: > setClass("grandma", slots = c(a = "character")) > setClass("mother", slots = c(b = "matrix"), contains = "grandma") > setClass("daughter", slots = c(c = "list"), contains = &q...
2020 Feb 18
2
Possible Regression in setClassUnion between 3.5.0 and 3.6.0
...the global environment, everything acts as expected, however when I put the same code in the context of a package, selectMethod can no longer find the correct method. This first block below puts the code in the context of a package: fn <- "codefile.R" writeLines( c( "setClass('x', slots = list(slot ='character'))", "setClass('y', slots = list(slot ='character'))", "setClass('a', slots = list(slot ='character'))", "setClass('b', slots = list(slot ='character&...
2005 Nov 22
1
failure in `setClass' examples
Hello, Below is what I got running the examples from `setClass'. Could somebody please help explain why the last `setIs' call is returning the warning and whether this is expected? R> setClass("track", + representation(x="numeric", y="numeric")) [1] "track" R> setClass("track...
2017 Jun 06
2
surprisingly, S4 classes with a "dim" or "dimnames" slot are final (in the Java sense)
Hi, It's nice to be able to define S4 classes with slots that correspond to standard attributes: setClass("A1", slots=c(names="character")) setClass("A2", slots=c(dim="integer")) setClass("A3", slots=c(dimnames="list")) By doing this, one gets a few methods for free: a1 <- new("A1", names=letters[1:3]) names(a1)...
2016 Mar 18
2
unary class union of an S3 class
Hi, Short story ----------- setClassUnion("ArrayLike", "array") showClass("ArrayLike") # no slot setClass("MyArrayLikeConcreteSubclass", contains="ArrayLike", representation(stuff="ANY") ) showClass("MyArrayLikeConcreteSubclass") # 2 sl...
2005 Aug 18
2
Use of contains in S4 classes
setClass("B", representation=representation("B", extra="numeric)) setClass("B", representation=representation(extra="numeric"), contains="B") Are these the same? If not, how do they differ? What about setClass("B", representation=representa...
2012 Oct 18
1
S4 fails to initialize linear hierarchies with intermediate VIRTUAL classes
Initialization of this simple hierarchy A = setClass("A", representation(x="numeric")) setClass("B", contains=c("VIRTUAL", "A")) C = setClass("C", contains="B") fails (neat that setClass returns generators; I hadn't realized that before!) > C(A()) Error: evaluation...
2011 Feb 12
2
Linked List in R
Hi, I am trying to create a linked list in R by defining a class Node which has a instance variable Node. setClass("Node", representation(rate="numeric", nextNode="ANY")) The above works. But the following gives me a warning message. setClass("Node", representation(rate="numeric", nextNode="Node")) > > setClass("Node", representati...
2006 Oct 20
1
understanding virtual classes and extensions thereof
I am having some trouble creating a hierarchy of virtual classes (akin to the class structure in the 'Matrix' package). I think they arise from my not understanding the best way to specify virtual subclasses of a virtual class. please see questions below code. setClass("mom") setClass("kid1", representation("mom", "VIRTUAL")) setClass("kid2", representation("VIRTUAL"), contains = "mom") setClass("kid3"); setIs("kid3", "mom") (i) Are 'kid1' and 'kid2...
2012 Feb 15
1
Cannot use setClass() in Rscript
Greetings, I am creating a standalone executable script using Rscript and have run into problems when I define a new S4 class. Here is a small script that demonstrates my problem: #!/usr/bin/env Rscript # # toy.Rscript -- testing S4 class creation in an Rscript setClass("toy", representation(name = "character", price = "numeric"), prototype(name = "ball", price = 10.0) ) b <- new("toy") print(b) When I make this script executable and run it I get the following error: $ ./toy.R...
2009 Mar 29
1
Recent setClass fails where previous succeeded
These lines of code setClass("A", representation(x="numeric")) setMethod(initialize, "A", function(.Object, ...) stop("oops")) setClass("B", representation("A")) result in > setClass("B", representation("A")) Error in initialize(value, ...) :...
2007 Apr 19
2
setClass inside a function
Hello, I would like to create a function that gets passed a class name and then calls setClass, and a few other functions, inside. I have done this in the past with setmethod, creating accessors for all slots in a set of S4 classes. But setClass is choking when my function is called isnide a package, telling about an error in exists(cname, where). I assume this to be a problem with the envir...
2020 Feb 19
2
Possible Regression in setClassUnion between 3.5.0 and 3.6.0
...t the same code in the context of a package, > > selectMethod can no longer find the correct method. This first block below > > puts the code in the context of a package: > > > > fn <- "codefile.R" > > writeLines( > > c( > > "setClass('x', slots = list(slot ='character'))", > > "setClass('y', slots = list(slot ='character'))", > > "setClass('a', slots = list(slot ='character'))", > > "setClass('b', s...
2011 Jan 28
2
help with S4 objects: trying to use a "link-glm" as a class in an object definition
Hi, I'm trying to make a new S4 object with a slot for a "link-glm" object. R doesn't like me have a slot of class "link-glm" > class(make.link("probit")) [1] "link-glm" > setClass("a",representation(item="link-glm")) [1] "a" Warning message: undefined slot classes in definition of "a": item(class "link-glm") > fa <- function() { + new("a",item=make.link("probit")) + }> > fa() Error in valid...
2009 Jun 30
1
S4 class redefinition
I haven't found much on S4 class redefinition; the little I've seen indicates the following is to be expected: 1. setClass("foo", ....) 2. create objects of class foo. 3. execute the same setClass("foo", ...) again (source the same file). 4. objects from step 2 are now NULL. Is that the expected behavior (I ran under R 2.7.1)? Assuming it is, it's kind of unfortunate. I can wrap my setClass c...
2003 Jun 24
1
S4 method setClass prototype definition question
...# R 1.7.1 on Debian Linux (compiled with gcc 3.2.2) > version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major 1 minor 7.1 year 2003 month 06 day 16 language R ## define a base class (virtual) without prototype setClass("IDataType", representation("VIRTUAL", valid="logical"), validity=NULL, sealed=TRUE) ## same now with prototype definition setClass("IDataType1", representation("VIRTUAL&quot...