The wording of the question โpass x through ...โ suggests that you think this will perform โcomposition,โ that is, the sequential application of functions to the results of previous applications. None of the solutions you offer will do this, although you can redo your for loop to do this. Take a look at the ?funprog man page, which I shamelessly quote in part:
## Iterative function application: Funcall <- function(f, ...) f(...) ## Compute log(exp(acos(cos(0)) Reduce(Funcall, list(log, exp, acos, cos), 0, right = TRUE)
Compare the results of the for loop version with the Reduce version:
> flist <- list(log, exp, acos, cos) > arg <- 0; for (f in flist) {arg <- f(arg)} > arg [1] 6.123234e-17 > Funcall <- function(f, ...) f(...) > ## Compute log(exp(acos(cos(0)) > Reduce(Funcall, list(log, exp, acos, cos), 0, right = TRUE) [1] 0
This shows what <something> actually happens:
arg <- 0; for (f in flist) {arg <- f(arg);cat(arg,"\n")} -Inf 0 1.570796 6.123234e-17
But they do not match, since right=TRUE actually changes the order of application and explains the trivial difference in the final result. For comparison:
arg <- 0; for (f in rev(flist)) {arg <- f(arg);cat(arg,"\n")}