I have a function of two parameters, and from that I'd like to create a list of functions in one parameter, like this:
flist <- lapply(c(1,2), function(x) { function(y) x + y })
This is intended to create a list of two functions, the first of which adds one to its input; the second of which adds two to its input. But it doesn't work:
> flist[[1]](3)
[1] 5
> flist[[2]](3)
[1] 5
Both of the functions in the list add two to their input. I have workarounds, but they are ugly, and I'd like to understand what I'm doing wrong.