[R] lazy evaluation question

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Mon Jan 19 19:45:07 CET 2009


Peter Dalgaard wrote:

<snip>
> 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.

here's one example:

d = data.frame(a=1, b=2)

lapply(3, function(a) subset(d, select=a))
lapply(3, function(b) subset(d, select=b))
lapply(3, function(c) subset(d, select=c))

vQ




More information about the R-help mailing list