Displaying 20 results from an estimated 8000 matches similar to: "length of S4"
2005 Jan 18
1
"Attach" for S4 objects?
When passing a list as an argument to a function, I find it convenient
to attach it in the first line of th function code, then refer to the
components as A, B, etc. rather than as list$A, list$B, etc.
If I pass a S4 class object, is there a way to "attach" it, or do I have
to refer to the slots as object at A, objetc at B, etc.?
I could always make copies,
A <- object at A
2010 Apr 24
3
S4 Inheritance of environments
I looked through the documentation and the mailing lists and could not
find an answer to this. My apologies if it has already been answered.
If it has, a pointer to the relevant discussion would be greatly
appreciated.
Creating S4 classes containing environments exhibits unexpected
behavior/features.? These have a different in two ways:
1) slotName for the data: ".xData" instead of
2004 Nov 26
1
Testing for S4 objects
Dear r-help list members,
Is there a way to test whether an object is an S4 object? The best that I've
been able to come up with is
isS4object <- function(object) !(is.null(slotNames(object)))
which assumes that an S4 object has at least one slot. I think this is safe,
but perhaps I'm missing something.
Thanks,
John
--------------------------------
John Fox
Department of
2004 Nov 26
1
Testing for S4 objects
Dear r-help list members,
Is there a way to test whether an object is an S4 object? The best that I've
been able to come up with is
isS4object <- function(object) !(is.null(slotNames(object)))
which assumes that an S4 object has at least one slot. I think this is safe,
but perhaps I'm missing something.
Thanks,
John
--------------------------------
John Fox
Department of
2009 Aug 17
2
S4: inheritance of validity methods?
Dear Developers,
In current implementation of validity method, objects are first coerced to
superclass (slots are striped). Thus, it is not possible to write validity
method which would perform some checks on children slots.
Say, I want to check if number of slots in a class is equal to "n":
setClass("A", representation(a="numeric", n="integer"),
2015 May 28
3
S4 inheritance and old class
Hey everyone,
I would like to develop a package using S4 classes.
I have to define several S4 classes that inherits from each others as
follow:
# A <- B <- C <- D
I also would like to define .DollarNames methods for these class so, if I
have understood well, I also have to define an old class as follow:
# AOld <- A <- B <- C <- D
setOldClass(Classes = "AOld")
2011 Nov 18
1
S4 : defining [<- using inheritance from 2 classes
Hi the list,
I define a class 'C' that inherit from two classes 'A' and 'B'. 'A' and 'B'
have no slot with similar names.
----------------
setClass(
Class="C",
contains=c("A","B")
)
To define the get operator '[' for class "C", I simply use the get of "A" or
"B" (the constante
2009 Jan 23
1
"for" loop wiht S4 Objects
Hi all,
I'm working with the S4-Class system and I have a little problem with
Implementing iteration functionality in my S4 class but it don't work:
> setClass("foo",representation(bar="list"))
> x <- new("foo",bar=list(1,2,3))
>for(e in x) cat(e)
invalid type/length (S4/1) in vector allocation
But when I extend from a
2009 Dec 03
1
S4 Classes, nested objects and references
Hi all,
I'm currently programming my first complete package in S4. (thanks to
Christophe Genolini for the nice introduction he wrote). I have an
object "Data" with a number of slots. One of those slots is "meteo".
Now "Meteo" is on itself a class with again a number of slots (like
rainfall, temperature,..., you get the picture).
I defined the slot
2011 Jun 04
1
S4 class, passing argument names to function, modify original
Hello, an S4 class "Foo" is defined with a setter, $. For several reasons, the setter calls a function, .foo.update(). However, bypassing the argument names of the setter does not work. Question 1: Why not and how can I fix this? Question 2: What is the way to define either the function or the setter to modify the original object (not returning the modified copy of it an overwrite the
2011 Sep 10
3
Very slow using S4 classes
Hi everybody!
I'm creating an object of a S4 class that has two slots: ListExamples, which
is a list, and idx, which is an integer (as the code below).
Then, I read a data.frame file with 10000 (ten thousands) of lines and 10
columns, do some pre-processing and, basically, I store each line as an
element of a list in the slot ListExamples of the S4 object. However, many
operations after this
2008 Mar 20
1
S4 : package creation
Hi the list,
Using S4, how can we create a package? In "S4 Classes in 15 pages, more
or less", they put all the classes definition in a function that will be
called at the opening of the library and they add "by hand" a Rd file.
Is it the only way ? Is there something like "S4.package.skeleton"?
Thanks
Christophe
2008 Mar 18
1
S4 : dumpMethod
Hi the list,
I almost finished the green book (chapter 7 and 8 on S4), this is
probably one of my last question :-)
I hope you will not miss them to much !
Here is my today nighmare: I do not manage to use dumpMethod :
setClass("A",representation(a="numeric"))
setMethod("plot","A",function(x,y,...){cat("AAAAA\n")})
2010 Mar 08
1
setClass or setValidity?
Hi,
I'm reading up on S4 classes *). There seem to be at least two ways of input validation:
setClass() (using the 'validity' argument) and setValidity(). Is it a matter of taste which function is used? Or should more complex validation code better be put in a setValiditity call?
*) A (Not So) Short Introduction to S4 Object Oriented Programming in R
V0.5.1 Christophe Genolini
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])
2009 Jun 18
1
validObject throws non-caught error when slot doesn't exist
I have been retooling an S4 class definition to include another slot and
have found that the methods::validObject function (defined in
methods/R/SClasses.R) in R-devel throws an error that isn't caught
internally (and thus not controllable by 'test' argument) when
retrieving a non-existent slot. The offending line of code is shown below:
> validObject
function (object, test =
2008 Mar 17
1
setAs vs setIs
Hi the list
I am fighting with the twins setAs and setIs...
Here are some questions and comments (comments to myself but that migth
be wrong, it is why I am posting them)
1. Very surprising : using setIs define 'is', 'as<-' but not 'as' ???
2. Using setAs define 'as', 'as<-' but not 'is'...
What surprise me is that as<- can be define by
2017 Jun 06
1
surprisingly, S4 classes with a "dim" or "dimnames" slot are final (in the Java sense)
I've fixed this and will commit soon.
Disregard my dim<-() example; that behaves as expected (the class needs a
dim<-() method).
Michael
On Tue, Jun 6, 2017 at 5:16 AM, Michael Lawrence <michafla at gene.com> wrote:
> Thanks for the report. The issue is that one cannot set special attributes
> like names, dim, dimnames, etc on S4 objects. I was aready working on this
>
2008 Mar 30
1
package.skeleton.S4
Hi the devel list.
I am adapting the package.skeleton to S4 classes and methods
I would have been very proud to post a new working function on this list.
Unfortunately, I do not manage to solve all the problems. Mainly
- sys.source does not compile a file with setClass
- dumpMethod does not exists yet
In the following code, thise two problems are notified by a line
#################
Still
2006 Dec 12
1
S4 'properties' - creating 'slot' functions?
Dear R users!
Several languages like C# or VB allow one to create properties; typically
these are under 'get', 'set' tags. My question is this really, what are
similar or comparable strategies in R, and what might be preferred? I have a
couple of situations where I want a certain computation to belong to a
class, but I do not really want to seperate it out to a stand-alone