Why is the behavior different for the latter two? It seems to me they should all give identical output (1, 2).
myFunc = function(i) {
return(function() { return(i) })
}
mF1 = myFunc(1);
mF1() #1
mF2 = myFunc(2);
mF1() #1
mF2() #2
myList = list()
for(i in 1:2) {
myList[[i]] = myFunc(i)
}
myList[[1]]() #2
myList[[2]]() #2
applyList = lapply(c(1,2), myFunc)
applyList[[1]]() #2
applyList[[2]]() #2
Thanks.