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

Reply via email to