I want to create a wrapper function that replaces some default arguments.
Here's the core of the problem I'm struggling with:
Error in localWindow(xlim, ylim, log, asp, ...) : formal argument "cex" matched by multiple actual arguments
Now a little context. Suppose I define a wrapper function for a graph as follows:
myplot <- function(x, ... ) { plot(x, cex= 1.5, ... ) }
If I call myplot( 1:10, cex= 2 ) , I will get the above error. I know I can turn ... into a list
l <- list(...)
and then I could do
if( is.null( l[["cex"]] ) ) l[["cex"]] <- 2
However, how can I βpasteβ this list back into the ellipsis argument? Something like (I know this won't work):
... <- l
EDIT: I could use the default values ββin myplot definition (as suggested in the answer from @Thomas), but I don't want to: the function interface will be cluttered. I think I could define a helper function:
.myfunchelper <- function( x, cex= 2.0, ... ) { plot( x, cex= cex, ... ) } myfunc <- function( x, ... ) { .myfunchelper( x, ... ) }
But (i) he is less elegant and (ii) does not satisfy my curiosity.
January
source share