I have the following R Code (the last part of this question), after the last line I expect to get a list of 4 "retFun" functions, each initialized with a different x so that I get the following result
funList[[1]](1) == 7 #TRUE
funList[[2]](1) == 8 #TRUE
And so on, but what I seem to get is
funList[[1]](1) == 10 #TRUE
funList[[2]](1) == 10 #TRUE
As if each function in the list has the same x value
creatFun <- function(x, y)
{
retFun <- function(z)
{
z + x + y
}
}
myL <- c(1,2,3,4)
funList <-sapply(myL, creatFun, y = 5)