Skip to content
Prev 14155 / 398503 Next

Weird feature when creating function lists with apply

Uffe H?gsbro Thygesen <uht at dfu.min.dk> writes:
This should work too:
f3 <- function(a) {a;function(x) a*x}
apply(as.array(1:4),1,f3)[[2]](1)

It is essentially the same situation that caused Luke Tierney
substantial headscratching recently. The key is lazy evaluation.
Here's part of the conversation from then:

[Snip from email from Luke]
On Wed, Aug 29, 2001 at 11:25:54PM +0200, Peter Dalgaard BSA wrote:
Now imagine getting bitten by this while experimenting with some new
threading code, which is of course then the prime suspect for all bad
things that happen, and you can see why Duncan and I were tearing our
hair out for a bit :-).