[R] lazy evaluation question

Gabor Grothendieck ggrothendieck at gmail.com
Mon Jan 19 18:45:30 CET 2009


On Mon, Jan 19, 2009 at 12:40 PM, Peter Dalgaard
<p.dalgaard at biostat.ku.dk> wrote:
> Gabor Grothendieck wrote:
>>
>> Note that
>>
>> rm(i)
>> for(j in 1:4) F(j)
>>
>> raises an error due to scoping issues.
>
> Yes. This has nothing to do with lazy evaluation, and everything to do with
> scoping: f is not defined in the scope of F, so does not know about its
> variables (nor those in the implicit loop of lapply()).
>
> Notice also that in
>
> lapply(1:4,function(i) F(i))
>
> it would be pretty weird if lapply would behave differently depending on the
> name of formal arguments of the function, i.e. if
>
> lapply(1:4,function(meep) F(meep))
>
> gave a different result. And f() depends on looking for a variable i outside
> of the function.


I believe that is what I was already referring to when I referred to
"scoping issues".
Since "not works" was never defined in the original post its hard to
know what the
problem being asked is but it might have been confusion over the
different uses of i.




More information about the R-help mailing list