Re: [Rd] iterated lapply

2015-02-23 Thread Duncan Temple Lang
Use force() (or anything that evaluates mycondition, e.g. your print): function(mycondition) { force(mycondition) function(i) mycondition * i } within the lapply() loop. Not a bug, but does surprise people. It is lazy evaluation. D. On 2/23/15 12:57 PM, Daniel Kaschek wrote: > Hi everyb

Re: [Rd] iterated lapply

2015-02-23 Thread Duncan Murdoch
On 23/02/2015 3:57 PM, Daniel Kaschek wrote: > Hi everybody, > > with the following code I generate a list of functions. Each function > reflects a "condition". When I evaluate this list of functions by > another lapply/sapply, I get an unexpected result: all values coincide. > However, when I unc

Re: [Rd] iterated lapply

2015-02-23 Thread Jeroen Ooms
On Mon, Feb 23, 2015 at 12:57 PM, Daniel Kaschek wrote: > Is this a bug or a feature? I think it is a bug. If we use substitute to inspect the promise, it appears the index number is always equal to its last value: vec <- c("foo", "bar", "baz") test <- lapply(vec, function(x){ function(){x} })

Re: [Rd] iterated lapply

2015-02-23 Thread Eduardo Arino de la Rubia
Greetings! I thought it was a lazy evaluation thing. I added "force" around mycondition and everything worked as expected. Cheers! On Mon Feb 23 2015 at 1:47:20 PM Jeroen Ooms wrote: > On Mon, Feb 23, 2015 at 12:57 PM, Daniel Kaschek > wrote: > > Is this a bug or a feature? > > I think it is

[Rd] iterated lapply

2015-02-23 Thread Daniel Kaschek
Hi everybody, with the following code I generate a list of functions. Each function reflects a "condition". When I evaluate this list of functions by another lapply/sapply, I get an unexpected result: all values coincide. However, when I uncomment the print(), it works as expected. Is this a bug o