[R] Using the ``...'' argument.

Rolf Turner rolf at math.unb.ca
Fri Nov 8 23:35:40 CET 2002


Suppose that I have a function fff which calls a couple of functions
foo and bar, and that foo takes optional arguments a and b, and bar
takes optional arguments u and v.

Is there an elegant way of passing ***both*** sets of optional
arguments via a ``...'' argument for fff?

I'd like to be able to have a structure like:

	fff(x,y,z,...) {
              .
	a1 <- foo(x,y,...)
	b1 <- bar(z,...)
              .
	}

and be able to give calls such as

	w1 <- fff(x,y,z,a=2,b=3,u=4,v=5)
	w2 <- fff(x,y,z,a=2,v=5)         # Letting b take its default value
                                         # in foo() and u take its default
					 # value in bar()
	w3 <- fff(x,y,z,a=2,b=3)         # Letting both u and v take their
					 # default values in bar()

and so on.  This of course doesn't work --- complaints about
``unused arguments'' are generated and fff() falls over.

One workaround that I can think of is

	fff(x,y,z,...) {
              .
	tmp <- list(x,y,...)
	tmp[c("u","v")] <- NULL
	a1 <- do.call("foo",NULL)
	tmp <- list(z,...)
	tmp[c("a","b")] <- NULL
	b1 <- do.call("bar",tmp)
              .
	}

but this is pretty kludgy.  Is there a better way?  Am I overlooking
something obvious?

					cheers,

						Rolf Turner
						rolf at math.unb.ca
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list