[R] pass functions and arguments to function

Hao Cen hcen at andrew.cmu.edu
Tue Dec 29 21:08:53 CET 2009


Hi,

I wonder how to pass several functions and their arguments as arguments to
a function. For example, the main function is

f = function(X  ) {
   process1(X)
   ...


   process2(X)
}

I have a few functions that operate on X, e.g. g1(X, par1), g2(X, par2),
g3(X, par3).  par1, par2 and par3 are parameters and of different types. I
would like to pass g1, g2, g3 and their arguments to f and g1, g2, g3 may
appear to be in different orders. So that final effect of the passing is

f = function(X  ) {
   process1(X)
   g1(X, par1)
   g2(X, par2)
   g3(X, par3)
   process2(X)
}

If I pass g2(X, par2),g3(X, par3), g1(X, par1) to f, I would expect to get
the effect of
f = function(X  ) {
   process1(X)
   g2(X, par2)
   g3(X, par3)
   g1(X, par1)
   process2(X)
}

Appreciate any suggestions.

thanks

Jeff


ps please ignore my previous blank subject email. It was accidentally sent
before the letter was completed.




More information about the R-help mailing list