[Rd] Replacing slot of S4 class in method of S4 class?

cstrato cstrato at aon.at
Fri Mar 30 22:45:38 CEST 2007


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), ...) {
       object at myname <- myname;
   #or:    myName(object) <- myname
   }
   setMethod("mymethod", "MyClass", mymethod.MyClass);

Furthermore, I have a replacement method:
setReplaceMethod("myName", signature(object="MyClass", value="character"),
   function(object, value) {
      object at myname <- value;
      return(object);
   }
)

I know that it is possible to call:
   myName(myclass) <- "newname"

However, I want to replace the value of slot "myname" for object "myclass"
in method "mymethod":
   mymethod(myclass,  myname="newname")

Sorrowly, the above code in method "mymethod" does not work.

Is there a possibility to change the value of a slot in the method of a 
class?

Best regards
Christian
_._._._._._._._._._._._._._._._
C.h.i.s.t.i.a.n S.t.r.a.t.o.w.a
V.i.e.n.n.a       A.u.s.t.r.i.a
_._._._._._._._._._._._._._._._



More information about the R-devel mailing list