Re: [R] functional (?) programming in r

From: Wacek Kusnierczyk <>
Date: Tue, 18 Nov 2008 11:22:18 +0100

> On Mon, Nov 17, 2008 at 7:33 PM, Wacek Kusnierczyk
>> ...what i would (r-naively) expect is that lapply for-loops over an index variable, and each promise picks from the list a value at that index....

let me make this line more clear:

funcs = lapply(1:2, function(i) function() i)

would make an environment in which 1:2 would be bound to some variable (say, v) and each closure in funcs would have in its own closure environment an unevaluated promise with an expression involving the variable (v) and an index *value*. that is, funcs[[1]] would have a promise with the expression "v[[1]]"; when forced, the promise would get the value 1 (since v is c(1,2), and v[[1]] is 1).

this would make for one way to solve my original problem (without forcing me to force the promises myself). but this depends on an assumption on how lapply works, which seems inaccurate. the other solution (where the promises corresponding to i inside each closure are forced when the closure is created) appears better, but this is guesswork which needs careful examination.

vQ mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Tue 18 Nov 2008 - 10:32:19 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 18 Nov 2008 - 11:30:25 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive