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()) > > } > > > > f doesn't need to be in the loop, it just needs to be defined in the same > environment as i was defined in. Loops in R don't create new local frames. >
That's a good point. Do you know if R will optimize out constant expressions from a loop? ______________________________________________ R-help@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.