I'm seeing strange behavior with the Curry function from library(roxygen). Here's a minimal example:
library(roxygen)
library(foreach)
f <- function(x,y,z) { return(x+y+z) }
fns <- list()
foreach(i=c(1:10)) %do% {
f[[i]] <- Curry(Curry(f,i),i)
}
In this case the call
f[[1]](0)
returns 11. I expect 2.
There are 2 fixes that don't make any sense to me - one is to flatten the loop, as in
fns <- list()
fns[[1]] <- Curry(Curry(f,1),1)
fns[[2]] <- Curry(Curry(f,2),2)
...
That works. In addition, putting a single function evaluation in the original loops works - as in
fns <- list()
foreach(i=c(1:10)) %do% {
f[[i]] <- Curry(Curry(f,i),i)
f[[i]](27)
}
We then have
f[[1]](0) = 2.
What's going on?