9
In the book Advanced R, to chapters 10 and 11, the author defines Function Factory as:
"a Factory for making new functions"
Translation Google Translate: a factory to do new functions.
And closure as:
"functions returned by Another Function"
Translation Google Translate: functions returned by another function.
So a Function Factory is a function that creates closures? For example:
myfun <- function(x) {
funs <- c(mean, median, sd, mad, IQR)
lapply(funs, function(f) f(x, na.rm = TRUE))
}
can be considered a Function Factory. Whereas: myfun
can be considered a closure, for:
abc <- 1:10
myfun(abc)
I was doubtful about these concepts, which seem to be related.