Re: [R] How to change the value of a class slot

From: Thomas Petzoldt <thpe_at_hhbio.wasser.tu-dresden.de>
Date: Fri 10 Jun 2005 - 05:37:32 EST

Ross Boylan wrote:
>
> I believe your example assumes that foo is updating the outer a by
> "cheating" and directly modifying enclosing environments. (I figure it
> also needs to get the name of its actual argument to do this, which
> would also involve slightly dirty tricks.) This does seem to be the only
> way to do it in standard R.
>
> In contrast, I wanted something like
> foo<-function(formalArg){
> formalArg <- new value
> return something else
> }
> so that if I call foo(a), a has the new value after the call.
> Unfortunately for me, that doesn't work. Call-by-value semantics imply
> that it can't.

What about call by reference like this:

library(proto)

arg <- proto(x=1)

foo<-function(formalArg){

   formalArg$x <- formalArg$x + 1.23
   #return something else
}

foo(arg)

arg$x

[1] 2.23

Best regards

Thomas P.



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 Received on Fri Jun 10 05:49:27 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:28 EST