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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Using the ``...'' argument.
2 messages · Rolf Turner, Brian Ripley
Adding ... to the argument lists of foo and bar will allow your first solution to work.
On Fri, 8 Nov 2002, Rolf Turner wrote:
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._