Displaying 20 results from an estimated 10000 matches similar to: "S4 Slot assignment within function"
2013 Mar 01
1
S4-classes: Assignment of values to slots by reference
Dear R-users,
I am working on a project that uses S4-classes. At some point I encountered the problem - well known to R - that I have to pass 3 different objects to a function, that should modify several slots of them and of course there is no passing by reference in R.
Then I read this thread by Steve Lianoglou: https://stat.ethz.ch/pipermail/r-help/2010-August/250468.html, which offers from
2010 Aug 25
1
Change value of a slot of an S4 object within a method.
Dear all,
I have an S4 class with a slot "extra" which is a list. I want to be
able to add an element called "name" to that list, containing the
object "value" (which can be a vector, a dataframe or another S4
object)
Obviously
setMethod("add.extra",signature=c("PM10Data","character","vector"),
function(object,name,value){
2011 Apr 06
2
S4 generic functions/methods vs enclosures
Apologies for asking something that is probably very obvious, i just started
with S4 classes and i guess i am not finding documentation that lays out the
grammar rules and gives enough examples.
I understand that main method of writing a member function is to write a
generic function and setMethod for this particular class. This, however,
presumes that there is "virtuality" for this
2010 May 12
1
slot assignment in S4 classes
Hi R friends,
I'm still studying S4 classes and I have a question about slot assignment. Why would I have to use a special setter method [example 2 below] if I can assign data to a slot directly when I call new() [example 1 below]?
## first way to do it (the idiosyncratic way?)
setClass(Class = "TestClass", representation = representation(myDf = "data.frame"))
2011 Apr 05
1
super basic questions about S4 classes
Apologies for asking something that is probably super obvious, i just started
with S4 classes and i guess i am not finding documentation that layout the
grammar rules and give enough examples. Some questions i am having are these
1. I understand that main method of writing a member function is to write a
generic function and setMethod for this particular object. This, however,
presumes that there
2003 Feb 19
1
assign value to slot of S4 object
Dear list,
I noticed something while assigning a new value to the slot
of an object of class S4.
Apparently(*) this object is copied while the operation
is performed. Is it really wished ? (or did I miss something ?)
I use R-1.6.2:
> R.version
_
platform i686-pc-linux-gnu
arch i686
os linux-gnu
system i686, linux-gnu
status
2011 Jun 04
2
Interfacing a C++ class
Hello
Apologies for cross-posting, the discussion should (if) go to R-devel, but I also want to reach the rcpp-devel people.
My C++ class FOO is a module available through Rcpp, and it works fine and is -- so far -- bug free. With trying to further develop my R package, I thought it was a good idea to interface my C++ workhorse FOO with an S4 class Foo. After some long and not always insightful
2010 Sep 30
1
Assignment to a slot in an S4 object in a list seems to violate copy rules?
Dear R-developers
I came across the following issue, which I find strange:
setClass("A", representation(a = "numeric"))
B <- list()
myA <- new("A", a = 1)
B$otherA <- myA
B$otherA at a <- 2
myA at a
Assigning a new value to slot 'a' in the _copy_ of myA stored
in B$otherA changes the original value of myA -- this was
surprising to me, and I
2018 May 21
1
S4 class slot type S4 class
All,
I am considering creating an S4 class whose slots (2) are both S4 classes. ?Since an S4 slot can be an S3 class I figure this can be done. ?However, the correct syntax of which I am unsure. ?Reviewing the docs I have come to the following conclusion:
SetClass('myfoo',
? ? ? ? ? ? ? ? ? slots = (foo1, foo2))
Without a type I believe each slot is .Data. ?A get method on the above
2008 Dec 22
1
How to add a slot to S4 class of an existing package?
Dear all,
Since my package is based on S4 classes, I would like to know how to add
a slot to an existing S4 class without breaking the code of users of my
package.
Assume the following S4 class:
setClass("MyClass",
representation(name = "character",
type = "character",
data = "data.frame"
),
prototype(name =
2011 Apr 07
2
How to debug reference classes?
How do you debug methods of a reference class? I've been using mtrace, which
is excellent, but i cannot figure out how to mtrace a reference class
method. Maybe there is some other way to debug these, for example with
ordinary trace? for now i am only able to use options(error=recover), which
is not giving me idea where exactly in the code i am once i am stopped on an
error.
--
View this
2005 Apr 13
1
S4 extends a class, but .Data slot has different class
When I define an S4 class ("B" in the example below) that directly extends
another ("A" in the example below) , which in turn directly extends another
("character" in the example below), I find that the slot does not have the
class I specified in setClass(), it has the underlying class.
Is this an intended feature?
Briefly, the reason for using this type of
2007 May 28
2
S4 object slot of type 'call'
I'm using an S4 object with a slot of type 'call': I would like to be able to initialize
it with something like NULL or NA (indicating that there is no information in the slot)
but the value should comply with the fact that it must be of type call.
Is there any simple way to obtain this?
Thanks for any hint,
Roberto
--
<r/>
| Roberto Brunelli - [scientist at Fondazione
2006 Apr 12
1
S4 class slot names
Hi,
Why doesn't this work?
setClass("test",representation(names="character"))
tmp <- new("test")
tmp@names <- "a"
Error in "slot<-"(object, name, TRUE, value) :
'names' attribute [1] must be the same length as the vector [0]
Why does this work (replace names with name)?
2008 Nov 26
1
S4 slot containing either aov or NULL
Dear listmembers,
I would like to define a class with a slot that takes either an object
of class aov or NULL. I have been reading "S4 Classes in 15 pages more
or less" and "Lecture: S4 classes and methods"
#First I tried with list and NULL
setClass(listOrNULL")
setIs("list", "listOrNULL")
setIs("NULL", "listOrNULL")
#doesn't
2007 Mar 30
2
Replacing slot of S4 class in method of S4 class?
Dear all,
Assume that I have an S4 class "MyClass" with a slot "myname", which
is initialized to: myname="" in method("initialize"):
myclass <- new("MyClass", myname="")
Assume that class "MyClass" has a method "mymethod":
"mymethod.MyClass" <-
function(object, myname=character(0), ...) {
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])
2007 May 30
2
S4 assignment \alias and \usage
What is the Rd file alias and usage syntax for an S4 assignment method?
I have been trying variations on
\alias{TSdoc<-,default-method}
\usage{
\S4method{TSdoc}{default}(x) <- value
but so far I have not got it right according to various codoc, etc, checks.
Paul Gilbert
====================================================================================
La version fran?aise
2008 Mar 26
5
S4 slot with NA default
Hi
How do I specify an S4 class with a slot that is potentially numeric,
but NA
by default? I want the slot to be NA until I calculate its value
(an expensive operation, not needed for all applications). When
its value is
known, I will create a new object with the correct value inserted in
the slot.
I want "NA" to signify "not known".
My attempt fails because
2005 Jan 09
1
S4 class no longer accepts matrix in array slot under 2.0.1
I have an S4 class with a slot of class "array", and in upgrading to 2.0.1
(from 1.9.1) I have encountered a change in behaviour. This causes me some
difficulties if I want to allow 2-dimensional arrays in the slot.
The following (in 2.0.1) illustrates the point:
> setClass("foo",representation("array"))
[1] "foo"
> a <-