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

From: Barry Rowlingson <>
Date: Sat, 09 Apr 2011 20:27:35 +0100

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^a
>>     )
>>  }
>> to make it clear that you expect people to look at or change
>> fun's 'a'.

 Once you start doing a lot of that though you may as well go the whole OO hog and use the proto or R.oo packages...

Barry mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Sat 09 Apr 2011 - 19:30:50 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 09 Apr 2011 - 20:00:29 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive