Re: [R] Problem with the special argument '...' within a function

From: Liaw, Andy <andy_liaw_at_merck.com>
Date: Thu 17 Aug 2006 - 02:09:17 EST


I'm not sure if this is what you want, but simply add ... to the list of arguments for fun1 and fun2 would eliminate the error.

Andy

From: Hans-Joerg Bibiko
>
> Dear all,
>
> I wrote some functions using the special argument '...'. OK, it works.
>
> But if I call such a function which also called such a
> function, then I get an error message about unused arguments.
>
> Here's an example:
>
> fun1 <- function(x,a=1)
> {
> print(paste("x=",x))
> print(paste("a=",a))
> }
> fun2 <- function(y,b=2)
> {
> print(paste("y=",y))
> print(paste("b=",b))
> }
> myfun <- function(c, ...)
> {
> print(paste("c=",c))
> fun1(x=c,...)
> fun2(y=c,...)
> }
>
> This is OK.
> > myfun(c=3)
> [1] "c= 3"
> [1] "x= 3"
> [1] "a= 1"
> [1] "y= 3"
> [1] "b= 2"
>
> > myfun(c=3,a=4)
> [1] "c= 3"
> [1] "x= 3"
> [1] "a= 4"
> Error in fun2(y = c, ...) : unused argument(s) (a ...)
>
> I understand the error message because fun2 has no argument
> called 'a'.
>
> But how can I avoid this???
>
> I want to use this in order to be able to call myfun() with
> all arguments to control myfun(),fun1(), and fun2().
>
> Please help!
>
> Thanks,
>
> Hans
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu Aug 17 02:19:15 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 17 Aug 2006 - 04:27:03 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.