From: Wacek Kusnierczyk <Waclaw.Marcin.Kusnierczyk_at_idi.ntnu.no>

Date: Tue, 18 Nov 2008 11:22:18 +0100

R-help_at_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. Received on Tue 18 Nov 2008 - 10:32:19 GMT

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

R-help_at_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. 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 https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*