On 12-04-24 7:34 PM, Ali Tofigh wrote:
Many thanks to both Duncan and Bert for clarifying this. Having looked
carefully at what you both wrote, my conclusion is the following:
in this code below
f<- function(x) {function() {x}}
b<- lapply(1:3, f)
lapply does not actually call f with the values
Many thanks to both Duncan and Bert for clarifying this. Having looked
carefully at what you both wrote, my conclusion is the following:
in this code below
f <- function(x) {function() {x}}
b <- lapply(1:3, f)
lapply does not actually call f with the values 1, 2, and 3. Instead,
it calls f three
On 12-04-24 5:13 PM, Ali Tofigh wrote:
On Tue, Apr 24, 2012 at 16:57, Duncan Murdoch wrote:
I thought that
lapply calls f three times and returns a list with whatever f
returned. Is this not so?
That is so. In each case, f creates a function that looks in its enclosing
environment for the va
On Tue, Apr 24, 2012 at 16:57, Duncan Murdoch wrote:
>> I thought that
>> lapply calls f three times and returns a list with whatever f
>> returned. Is this not so?
>
> That is so. In each case, f creates a function that looks in its enclosing
> environment for the variable x to be returned.
>
>
On 12-04-24 4:22 PM, Ali Tofigh wrote:
This has been asked before, but I just cannot figure out why lapply
should behave this way given that R uses lazy evalution. Even after
reading (or at least trying to read) parts of the R language
definition.
f<- function(x) {function() {x}}
a<- list(f(1),
This has been asked before, but I just cannot figure out why lapply
should behave this way given that R uses lazy evalution. Even after
reading (or at least trying to read) parts of the R language
definition.
> f <- function(x) {function() {x}}
> a <- list(f(1), f(2), f(3))
> a[[1]]() # as expecte
6 matches
Mail list logo