[R] how to manipulate ... in the argument list

Duncan Murdoch murdoch.duncan at gmail.com
Wed May 11 12:45:42 CEST 2016


On 11/05/2016 4:45 AM, Witold E Wolski wrote:
> Hi,
>
> I am looking for a documentation describing how to manipulate the
> "..." . Searching R-intro.html gives to many not relevant hits for
> "..."
>
> What I want to do is something like this :
>
>
> image.2 <- function(x, col , ...){
>   # function is manipulating colors (adding a few)
>   # since it changes colors it needs to update breaks if defined.
>
>    breaks <- list(...)$breaks
>
>   if( !is.null( list(...)$breaks ) ){
>      #manipulate breaks
>
>     image(x, col, breaks = breaks ,...)
>
>    }else{
>       image(x,col ,...)
>    }
> }
>
> but in order to get it working I will need to remove breaks from ...
> since otherwise I am getting multiple defined argument for breaks.

If breaks is an argument that image.2 uses, you should just list it 
explicitly, and it won't become part of ... .

However, if you really want to do what you describe, you can do it using 
do.call.  Replace

image(x, col, breaks = breaks, ...)

with

dots <- list(...)
dots$breaks <- NULL
do.call(image, c(list(x, col, breaks = breaks), dots))

>
> So how to manipulate the "..." argument? Or should I use a different pattern

I'd recommend a different pattern, i.e. include breaks as an argument, 
and possibly use is.missing(breaks) to determine when it has not been used.

Duncan Murdoch



More information about the R-help mailing list