Re: [R] outputting functions in lapply

2009-12-07 Thread baptiste auguie
Hi, I was about to send the exact same answer as you just received, so I'll add a note instead. Your problem looks a bit like Currying, Curry <- # original from roxygen function (f, ..., .left=TRUE) { .orig = list(...) function(...){ if(.left) {args <- c(.orig, list(...))} else {

Re: [R] outputting functions in lapply

2009-12-07 Thread Duncan Murdoch
On 07/12/2009 8:53 AM, Rune Schjellerup Philosof wrote: How come the k is 3 in all of this output? I expected it to be equal to r. > tmp3 <- lapply(1:3, function(k) function(r) print(paste(r, "<- r | k ->", k))) > for (i in 1:3) { tmp3[[i]](i) } [1] "1 <- r | k -> 3" [1] "2 <- r | k -> 3" [1] "3

[R] outputting functions in lapply

2009-12-07 Thread Rune Schjellerup Philosof
How come the k is 3 in all of this output? I expected it to be equal to r. > tmp3 <- lapply(1:3, function(k) function(r) print(paste(r, "<- r | k ->", k))) > for (i in 1:3) { tmp3[[i]](i) } [1] "1 <- r | k -> 3" [1] "2 <- r | k -> 3" [1] "3 <- r | k -> 3" -- Med venlig hilsen Rune Schjellerup P