Try this:
f <- function(env = parent.frame()) env$x
g <- function(x=1) f()
x <- 2
g() # 1
On Wed, Jan 21, 2009 at 5:45 PM, Yi Zhang <yizhang84 at gmail.com>
wrote:> Hello,
>
> I'm writing a function like this:
>
> f<-function(x,y,...) {
> ...
> assign(x,y,envir=?)
> }
>
> I need the caller (of f) 's environment for the "?" so that
the
> assignment is done at the right place. To be specific, when the code
> "f(x,1)" appears in environment A, I need the assignment of 1 to
x
> happen in environment A. So my question is how to get the correct
> environment?
>
> Thanks for any suggestions!
>
> ______________________________________________
> R-help at r-project.org 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.
>