Re: [R] Help with using 'get' function and variable scope

2008-04-18 Thread Gabor Grothendieck
If you define your functions in the loop you can it directly since then the scoping rules work in your favor: for(i in 1:4) { f - function() i*i print(f()) } or via lapply: F - function(i) { f - function() i*i; print(f()) } lapply(1:4, F) Often the sort of situation you discuss is really

Re: [R] Help with using 'get' function and variable scope

2008-04-18 Thread Duncan Murdoch
On 18/04/2008 7:27 AM, Gabor Grothendieck wrote: If you define your functions in the loop you can it directly since then the scoping rules work in your favor: for(i in 1:4) { f - function() i*i print(f()) } f doesn't need to be in the loop, it just needs to be defined in the same

Re: [R] Help with using 'get' function and variable scope

2008-04-18 Thread Gabor Grothendieck
On Fri, Apr 18, 2008 at 7:49 AM, Duncan Murdoch [EMAIL PROTECTED] wrote: On 18/04/2008 7:27 AM, Gabor Grothendieck wrote: If you define your functions in the loop you can it directly since then the scoping rules work in your favor: for(i in 1:4) { f - function() i*i print(f()) }

Re: [R] Help with using 'get' function and variable scope

2008-04-18 Thread Duncan Murdoch
On 4/18/2008 9:19 AM, Gabor Grothendieck wrote: On Fri, Apr 18, 2008 at 7:49 AM, Duncan Murdoch [EMAIL PROTECTED] wrote: On 18/04/2008 7:27 AM, Gabor Grothendieck wrote: If you define your functions in the loop you can it directly since then the scoping rules work in your favor: for(i in

[R] Help with using 'get' function and variable scope

2008-04-17 Thread Peter Waltman
Hi - I'm having a really hard time w/understanding R's get function, and would appreciate any help with this. Specifically, I'm using a for loop to call a function. I'd like the function to have access to the variable being incremented in the for-loop, i.e. t.fn - function() return( get( i ) )