Try this:
myassign <- function(x, val, env = parent.frame())
assign(deparse(substitute(x)), val, env)
myassign(x, 3)
x # 3
On Wed, Jan 21, 2009 at 8:03 PM, Yi Zhang wrote:
> On Wed, Jan 21, 2009 at 5:57 PM, Gabor Grothendieck
> wrote:
>> Try this:
>>
>> f <- function(env = parent.frame()) env$x
On Wed, Jan 21, 2009 at 5:57 PM, Gabor Grothendieck
wrote:
> Try this:
>
> f <- function(env = parent.frame()) env$x
Thanks. What if the x in "env$x" is an argument passed in? e.g. f <-
function(x, env=parent.frame()) { #assign to env$x ? }
> g <- function(x=1) f()
> x <- 2
> g() # 1
>
> On Wed, J
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 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
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
4 matches
Mail list logo