Skip to content
Prev 246925 / 398502 Next

Evaluation of variable assigned to a function name

On 10.01.2011 14:56, carol white wrote:
Well, both versions will need the same number of arguments unless you 
want to pass the as well. Example:

bar <- function(arglist, foo){
     if(missing(foo)) foo <- my.func
     v <- do.call(foo, arglist)
     return(v*3)
}

my.func <- function(x,y,z){
     return(x+y+z)
}

my.func.user <- function(x){
    return(x)
}


Then you can do, e.g.:

bar(arglist=list(x=1, y=2, z=3))

bar(arglist=list(x=1), foo=my.func.user)


Hope this clarifies the idea.

Best,
Uwe