Skip to content
Prev 256078 / 398506 Next

Two functions as parametrs of a function.

On 07/04/2011 7:45 AM, Kenneth Roy Cabrera Torres wrote:
You don't want to unlist those.  Leave them as lists, and use the 
do.call() function for the calls.  For example,

localfun1 <- function() do.call(fun1, c(list(n), par1))
Calling force() is only useful for arguments to your function:  it kicks 
the evaluator, so it's not so lazy.   Since p1 and p2 were calculated 
earlier, there's no need to force them.  You might need to force n, 
since it is only used in the localfun1 and localfun2 calls, and if the 
argument to f2 changes before you make those calls, the wrong value will 
be used.  That's pretty unlikely with your code, but since fun1 and fun2 
can do anything, it's safest to fix the value of n before you call 
them.  The same argument applies to fun1 and fun2 themselves.

Duncan Murdoch