> myfun2 <- function(method, x, ...) {
+ method.call <- do.call("call", list(method, x, ...))
+ eval(method.call)
+ }
> myfun2('sqrt',2)
[1] 1.414214
>If you don't need the call object, you can just use do.call() directly (this is the same as Andy Liaw's suggestion):
> myfun <- function(method, x, ...) {
+ do.call(method, list(x, ...))
+ }
> myfun('sqrt',2)
[1] 1.414214At Thursday 01:03 PM 3/11/2004, [EMAIL PROTECTED] wrote:
I am trying to write a function, which would allow to call various methods and would pass to them extra arbitrary parameters. My first attempt was to use call() as illustrated below, but apparently '...' cannot be used in such context.
How can this be achieved ?
Best regards,
Ryszard
> myfun <- function(method, x, ...) { + v <- eval(call(method, x, ...)) + } > method = 'sqrt' > myfun('sqrt',2) Error in eval(call(method, x, ...)) : ... used in an incorrect context > eval(call(method, 2, ...)) Error in eval(call(method, 2, ...)) : ... used in an incorrect context > eval(call(method, 2)) [1] 1.414214
______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
