similar to: Extending [ method to S4 class and drop argument (PR#9211)

Displaying 20 results from an estimated 7000 matches similar to: "Extending [ method to S4 class and drop argument (PR#9211)"

2012 Mar 15
1
Extending a group of S4 classes by setClassUnion ?
Hi, I would like to create some S4 classes as follows setClass("Father",representation(name="character")) setClass("Son1",contains="Father",representation(par="numeric")) setClass("Son2",contains="Father",representation(par="logical")) Son1<-new("Son1") Son1 at name<-"Son1" Son1 at par<-3
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" is
2006 May 11
2
S4 initialize methods, unexpected recursive callNextMethod
Hi, Given a simple three class hierarchy: A <-- B <-- C I want to define an initialize method for each class such that when I call new("C", x=5), the initialize methods for A and B are used to incrementally build the object. When I do what seems obvious to me using callNextMethod, I get an infinite recursion. An example follows... setClass("A",
2010 Mar 16
1
Problem with S3 to S4 transition
Hello to everybody I am developing a package using R and have the following problem: I used to work in a mixture of S3 and S4 mechanism environment: as a matter of fact, I used to define my classes (say "DB" for illustration) using the setClass function (with representation field), and I was using the S3 implicit mechanism writing the functions: print.DB and plot.DB. Recently, I
2010 Jun 23
2
format: different S4 behavior in a package
R-Devel-ers: I have an S4 method that simply formats an object: setGeneric("formatMe", function(x) standardGeneric("formatMe")) setMethod("formatMe", "ANY", function(x) format(x)) If I issue the above in an R session, then define an S4 class with its own format method, I get the desired result: > setClass("A",contains="numeric")
2013 Feb 05
1
S4 Classes and Initialize methods
Hello, I am trying to improve my skill on S4 classes. But there's something strange (to me) happening with "initialize" methods. This is probably a normal behaviour... but... something is unclear in my mind I declare two classes, namely "A", and "B", which has a slot of type A. The class "A" has an initialize method. What I do not understand is that
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
2005 Aug 05
1
S4 generating function
Can someone explain what the problem is when I use the generating function? And how to get debug() to stop in the Superclass initialize method? ---- source ----- setClass("Superclass", representation(id = "character"), contains = "VIRTUAL") setMethod("initialize", signature(.Object = "Superclass"),
2009 Oct 13
1
for loop over S4
Hello, Consider this : > setClass("track", representation(x="numeric", y="numeric")) [1] "track" > o <- new( "track", x = 1, y = 2 ) > for( i in o ){ + cat( "hello\n") + } Error: invalid type/length (S4/1) in vector allocation This happens at those lines of do_for: n = LENGTH(val); PROTECT_WITH_INDEX(v =
2004 Jun 02
3
S4 classes?
The following example, extracted from pp. 38-42 of Chambers (1998) Programming with Data (Springer), works for me in S-Plus 6.2 but not R 1.9.0pat, which returns the indicated error messages: > setClass('track', representation(x="numeric", y="numeric")) [1] "track" > tr1 <- new("track", x=1:3, y=4:6) > setMethod("plot", +
2006 Apr 07
4
setIs and method dispatch in S4 classes
Dear all, I have a question regarding setIs and method dispatch in S4 classes: Consider the following example: ##################################################### ## A02 "contains" A01 by setIs: setClass("A01", representation(a="numeric",b="numeric")) setClass("A02", representation(a="numeric",d="numeric"))
2008 May 10
2
Hashes as S4 Classes, or: How to separate environments
For learning purposes mainly I attempted to implement hashes/maps/dictionaries (Python lingua) as S4 classes, see the coding below. I came across some rough S4 edges, but in the end it worked (for one dictionary). When testing ones sees that the dictionaries D1 and D2 share their environments D1 at hash and D2 at hash, though I thought a new and empty environment would be generated each time
2005 Jun 20
3
How to define S4 methods for '['
Folks: This is a question about the S4 formal class system. Suppose I have a class, 'foo', defined by: setClass('foo',representation(dat='matrix', id='character') ) I wish to define a '[' method for foo that will extract from the 'dat' slot. I would have thought that the following would work, but it doesn't:
2015 May 10
2
S4 method dispatch sometimes leads to incorrect when object loaded from file?
Loading an S4 object from a file without first loading the library sometimes (?, the example below and actual example involves a virtual base class and the show generic) leads to incorrect dispatch (to the base class method). The attached package reproduces the problem. It has setClass("A") setClass("B", contains="A") setMethod("show", "A",
2020 Oct 05
2
S4 - inheritance changed by order of setClassUnion and setAs()
Dear colleagues, there is a behaviour with S4 (virtual) classes that I find very hard to understand: Depending on the position of setAs(), the tree 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
2004 Apr 19
3
How to write an S4 method for sum or a Summary generic
If I have a class Foo, then i can write an S3 method for sum for it: >setClass("Foo",representation(a="integer"));aFoo=new("Foo",a=c(1:3,NA)) >sum.Foo <- function(x,na.rm){print(x);print(na.rm);sum(x at a,na.rm=na.rm)} >sum(aFoo) But how do I write an S4 method for this? All my attempts to do so have foundered. For example
2008 Feb 29
1
inheritence in S4
Hi the list I define a class A (slot a and b), a class C (slot c and d) and a class E that inherit from A and B. I define print(A) and print(B). For print(C), I would like to use both of them, but I do not see how... Thanks for your help... Christophe ---------------------------------------------------------------- Ce message a ete envoye par IMP, grace a l'Universite Paris 10 Nanterre
2010 May 29
3
S4 dispatch for .DollarNames (utils)
Hello, I'm trying to make .DollarNames generic and implement a method for it in a package. .DollarNames is the function that is now called to get completion possibilities. My R code looks like this: setGeneric( ".DollarNames" ) setClass("track", representation(x="numeric", y="numeric")) ## A class extending the previous, adding one more
2006 Apr 12
1
yet another problem with S4 dispatch (with setClassUnion)
Dear John and Seth, dear R-devels, once again the question of method dispatch in S4 -- this time with setClassUnion(); taking up your advice in https://stat.ethz.ch/pipermail/r-devel/2006-April/037200.html https://stat.ethz.ch/pipermail/r-devel/2006-April/037201.html I have been too quick in stating that >setClassUnion()---at least in my case---solves the problem; > The problem arises
2006 Mar 01
2
Class & Method, S3 / S4
Hi I'm trying to create a class. However, I've some problems... I am used to program php. There I can create a new object and call a specific function of this object. In R, I hoped to create a class similar and then call the function like: Creating the Class: <CODE>----------------------------------- setClass("connect", representation(test="function")) )