Re: [R] best practice(s) for retrieving a local variable from a closure

2011-04-09 Thread Gabor Grothendieck
On Sat, Apr 9, 2011 at 3:27 PM, Barry Rowlingson wrote: > On Sat, Apr 9, 2011 at 6:29 PM, Benjamin Tyner wrote: > >>> The above feels a bit like snooping where I wasn't invited. >>> You could do something like >>>  mq <- function(a) { >>>     force(a) >>>     list(getA = function()a, >>>        

Re: [R] best practice(s) for retrieving a local variable from a closure

2011-04-09 Thread Barry Rowlingson
On Sat, Apr 9, 2011 at 6:29 PM, Benjamin Tyner wrote: >> The above feels a bit like snooping where I wasn't invited. >> You could do something like >>  mq <- function(a) { >>     force(a) >>     list(getA = function()a, >>          setA = function(newA) a <<- newA, >>          fun = function(x)x^

Re: [R] best practice(s) for retrieving a local variable from a closure

2011-04-09 Thread Benjamin Tyner
Thanks Bill and Gabor! William Dunlap wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Benjamin Tyner Sent: Friday, April 08, 2011 6:48 PM To: r-help@r-project.org Subject: [R] best practice(s) for retrieving a local

Re: [R] best practice(s) for retrieving a local variable from a closure

2011-04-08 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Benjamin Tyner > Sent: Friday, April 08, 2011 6:48 PM > To: r-help@r-project.org > Subject: [R] best practice(s) for retrieving a local variable > from a c

Re: [R] best practice(s) for retrieving a local variable from a closure

2011-04-08 Thread Gabor Grothendieck
On Fri, Apr 8, 2011 at 9:48 PM, Benjamin Tyner wrote: > Greetings, > > Say I have defined > >  mp <- function(a) function(x) x^a > >  f2 <- mp(2) > > and I would like to retrieve the "a" which is local to f2. Two options come > to mind; > >  get("a", envir=environment(f2)) >  eval(substitute(a), e

[R] best practice(s) for retrieving a local variable from a closure

2011-04-08 Thread Benjamin Tyner
Greetings, Say I have defined mp <- function(a) function(x) x^a f2 <- mp(2) and I would like to retrieve the "a" which is local to f2. Two options come to mind; get("a", envir=environment(f2)) eval(substitute(a), environment(f2)) I'm curious if one of these is preferred over the other