Dear R-help,
Can some one tell me how to do the following (if it's possible)?
Suppose I have a function like this:
f <- function(x, y, ...) {
## some code
g(x, y, ...)
## some more code
}
The problem is that g() may not understand everything that comes through in
"...". Is there a way to delete some component of "..." and
then pass it to
g()?
Here's the description of the real problem: f() is a panel.something
function, and g() is a model fitting function. Lattice passes
"panel.number" as part of "..." to f(), and g() complains
about unused
argument "panel.number".
I'd be very grateful for any help!
Cheers,
Andy
------------------------------------------------------------------------------
As Brian Ripley pointed out in a recent post, you can just give g() its own
"..." argument.
Regards,
Matt Wiener
-----Original Message-----
From: Liaw, Andy [mailto:andy_liaw at merck.com]
Sent: Friday, March 21, 2003 3:37 PM
To: 'r-help at stat.math.ethz.ch'
Subject: [R] manipulating "..." inside a function
Dear R-help,
Can some one tell me how to do the following (if it's possible)?
Suppose I have a function like this:
f <- function(x, y, ...) {
## some code
g(x, y, ...)
## some more code
}
The problem is that g() may not understand everything that comes through in
"...". Is there a way to delete some component of "..." and
then pass it to
g()?
Here's the description of the real problem: f() is a panel.something
function, and g() is a model fitting function. Lattice passes
"panel.number" as part of "..." to f(), and g() complains
about unused
argument "panel.number".
I'd be very grateful for any help!
Cheers,
Andy
----------------------------------------------------------------------------
--
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
----------------------------------------------------------------------------
--
Notice: This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that
may be confidential, proprietary copyrighted and/or legally privileged, and
is intended solely for the use of the individual or entity named on this
message. If you are not the intended recipient, and have received this
message in error, please immediately return this by e-mail and then delete
it.
============================================================================
------------------------------------------------------------------------------
I have a couple of slightly ugly functions to do this in my bbmisc
package:
clean.args <- function(argstr,fn,extrabad=NULL,dots.ok=TRUE) {
fnargs <- names(formals(fn))
if (length(argstr)>0 && !("..." %in% fnargs &&
dots.ok)) {
badargs <- !sapply(names(argstr),"%in%",c(fnargs,""))
argstr <- argstr[!badargs]
}
for (i in extrabad)
argstr[[i]] <- NULL
argstr
}
remove.args <- function(argstr,fn) {
fnargs <- names(formals(fn))
argstr[!(names(argstr) %in% fnargs)]
}
On Fri, 21 Mar 2003, Liaw, Andy wrote:
> Dear R-help,
>
> Can some one tell me how to do the following (if it's possible)?
>
> Suppose I have a function like this:
>
> f <- function(x, y, ...) {
> ## some code
> g(x, y, ...)
> ## some more code
> }
>
> The problem is that g() may not understand everything that comes through in
> "...". Is there a way to delete some component of
"..." and then pass it to
> g()?
>
> Here's the description of the real problem: f() is a panel.something
> function, and g() is a model fitting function. Lattice passes
> "panel.number" as part of "..." to f(), and g()
complains about unused
> argument "panel.number".
>
> I'd be very grateful for any help!
>
> Cheers,
> Andy
>
>
>
------------------------------------------------------------------------------
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
--
318 Carr Hall bolker at zoo.ufl.edu
Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker
Box 118525 (ph) 352-392-5697
Gainesville, FL 32611-8525 (fax) 352-392-3704
Thanks to those who responded. I finally got by with some pretty ugly hack (ceorcing ... to list, delete the unwanted part, add other arguments, and use do.call). Cheers, Andy> -----Original Message----- > From: Ben Bolker [mailto:ben at zoo.ufl.edu] > Sent: Friday, March 21, 2003 3:59 PM > To: Liaw, Andy > Cc: 'r-help at stat.math.ethz.ch' > Subject: Re: [R] manipulating "..." inside a function > > > > I have a couple of slightly ugly functions to do this in my bbmisc > package: > > clean.args <- function(argstr,fn,extrabad=NULL,dots.ok=TRUE) { > fnargs <- names(formals(fn)) > if (length(argstr)>0 && !("..." %in% fnargs && dots.ok)) { > badargs <- !sapply(names(argstr),"%in%",c(fnargs,"")) > argstr <- argstr[!badargs] > } > for (i in extrabad) > argstr[[i]] <- NULL > argstr > } > > remove.args <- function(argstr,fn) { > fnargs <- names(formals(fn)) > argstr[!(names(argstr) %in% fnargs)] > } > > > On Fri, 21 Mar 2003, Liaw, Andy wrote: > > > Dear R-help, > > > > Can some one tell me how to do the following (if it's possible)? > > > > Suppose I have a function like this: > > > > f <- function(x, y, ...) { > > ## some code > > g(x, y, ...) > > ## some more code > > } > > > > The problem is that g() may not understand everything that > comes through in > > "...". Is there a way to delete some component of "..." > and then pass it to > > g()? > > > > Here's the description of the real problem: f() is a > panel.something > > function, and g() is a model fitting function. Lattice passes > > "panel.number" as part of "..." to f(), and g() complains > about unused > > argument "panel.number". > > > > I'd be very grateful for any help! > > > > Cheers, > > Andy > > > > > > > -------------------------------------------------------------- > ---------------- > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > > > > -- > 318 Carr Hall bolker at zoo.ufl.edu > Zoology Department, University of Florida > http://www.zoo.ufl.edu/bolker > Box 118525 (ph) 352-392-5697 > Gainesville, FL 32611-8525 (fax) 352-392-3704 > >------------------------------------------------------------------------------
On Friday 21 March 2003 02:36 pm, Liaw, Andy wrote:> Dear R-help, > > Can some one tell me how to do the following (if it's possible)? > > Suppose I have a function like this: > > f <- function(x, y, ...) { > ## some code > g(x, y, ...) > ## some more code > }Why not (in the context you describe below) f <- function(x, y, panel.number, ...) { ## some code g(x, y, ...) ## some more code } ? (This is the trick usually used for the strip function in particular.)> The problem is that g() may not understand everything that comes through in > "...". Is there a way to delete some component of "..." and then pass it > to g()? > > Here's the description of the real problem: f() is a panel.something > function, and g() is a model fitting function. Lattice passes > "panel.number" as part of "..." to f(), and g() complains about unused > argument "panel.number". > > I'd be very grateful for any help! > > Cheers, > Andy > > > --------------------------------------------------------------------------- >--- > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> From: Deepayan Sarkar [mailto:deepayan at stat.wisc.edu] > On Friday 21 March 2003 02:36 pm, Liaw, Andy wrote: > > Dear R-help, > > > > Can some one tell me how to do the following (if it's possible)? > > > > Suppose I have a function like this: > > > > f <- function(x, y, ...) { > > ## some code > > g(x, y, ...) > > ## some more code > > } > > Why not (in the context you describe below) > > f <- function(x, y, panel.number, ...) { > ## some code > g(x, y, ...) > ## some more code > } > > ? (This is the trick usually used for the strip function in > particular.)Ah... Yes. It didn't come me to put unwanted argument as part of the formal parameters of the function to catch it. Very nifty! Thanks! Andy ------------------------------------------------------------------------------