From cstrato at aon.at  Fri Mar 30 22:45:38 2007
From: cstrato at aon.at (cstrato)
Date: Fri, 30 Mar 2007 22:45:38 +0200
Subject: [Rd] Replacing slot of S4 class in method of S4 class?
Message-ID: <460D76F2.1060300@aon.at>

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
_._._._._._._._._._._._._._._._



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