In response to the first question: Yes, you can use several functions, but the second and subsequent functions must be transferred to the first function, and then to the next function, etc. Therefore, functions must be encoded to accept additional arguments and pass them.
for instance
foo <- function(x, f1, ...) f1(x, ...) bar <- function(y, f2, ...) f2(y, ...) foobar <- function(z, f3, ...) f3(z) sapply(1:10, foo, f1 = bar, y = 2, f2 = foobar, z = 4, f3 = seq_len) > sapply(1:10, foo, f1 = bar, y = 2, f2 = foobar, z = 4, f3 = seq_len) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1 1 1 1 1 1 1 1 1 1 [2,] 2 2 2 2 2 2 2 2 2 2 [3,] 3 3 3 3 3 3 3 3 3 3 [4,] 4 4 4 4 4 4 4 4 4 4
This is a dumb example, but it shows how to pass additional arguments to foo() , initially as part of the argument ... sapply() . It also shows how to have foo() and subsequent functions accept additional arguments that need to be passed simply by using ... in the function definition and how the next function is called, for example. f2(y, ...) . Note. I also avoid positional matching problems and will name all the extra arguments provided by foo() .
Regarding question 2, I think that, as you explain, this makes the situation too complicated. For example, you duplicated the bits reg.data and reg.fcn in that iterations are repeated using sapply() , which is incorrect (this means that you iterate over three things in the vector c(1:n,reg.data,reg.fcn) , not over 1:n ).
sapply(1:n, fun, arg1, arg2) equivalent
fun(1, arg1, arg2) fun(2, arg1, arg2) .... fun(10, arg1, arg2)
while sapply(1:n, fun, arg1 = bar, arg2 = foobar) equivalent
fun(1, arg1 = bar, arg2 = foobar) fun(2, arg1 = bar, arg2 = foobar) .... fun(10, arg1 = bar, arg2 = foobar)