Sorry Martin. I had that line in my actual code. It did not work. I looked around all the google but it doesn't seem to have answer to this. Any ideas? Thank you.

- adschai

----- Original Message -----
From: Martin Morgan 
Date: Thursday, May 24, 2007 9:35 pm
Subject: Re: [R] Question about setReplaceMethod
To: adschai@optonline.net
Cc: r-help@stat.math.ethz.ch

> Hi Adschai --
> 
> You'll want to return the value whose slot you have modified:
> 
> setReplaceMethod("setX", "foo",
> function(this,value) {
> this@x <- value
> this # add this line
> })
> 
> Martin
> 
> adschai@optonline.net writes:
> 
> > Hi 
> > 
> > I have the code like I show below. The problem here is that I 
> have a
> > setReplacementMethod to set the value of my class slot. However,
> > this function doesn't work when I call it within another function
> > definition (declared by setMethod) of the same class. I do not
> > understand this behavior that much. I'm wondering how to make this
> > work? Any help would be really appreciated. Thank you.
> > 
> > setClass("foo", 
> > representation(x="data.frame", y="character"))
> > setGeneric("setX<-", function(this, value), 
> standardGeneric("setX<-"))
> > setReplaceMethod("setX", "foo",
> > function(this,value) {
> > this@x <- value
> > })
> > setGeneric("generateFrame", function(this), 
> standardGeneric("generateFrame"))> 
> setReplaceMethod("generateFrame", "foo",
> > function(this) {
> > frame <- read.csv(file="myfile.csv", header=T) # read some 
> input file
> > this@x <- frame # this doesn't replace the value for me
> > setX(this) <- frame # this doesn't replace the value for me
> > frame # instead I have to return the frame object
> > })
> > foo <- function(x,y) {
> > objFoo <- new("foo", x=data.frame(NULL), y="")
> > frame <- generateFrame(objFoo) # after this point, nothing got 
> assigned to objFoo@x
> > setX(objFoo) <- frame # this will work (why do I have to 
> duplicate this??) 
> > }
> > - adschai
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help@stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-
> project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> -- 
> Martin Morgan
> Bioconductor / Computational Biology
> http://bioconductor.org
> 

	[[alternative HTML version deleted]]

