[Rd] Changing "..." inside a function: impossible? desirable?

Tony Plate tplate@blackmesacapital.com
Tue Dec 17 23:00:04 2002


Another way of enabling more vesatile dot-args would be to allow an 
ordinary list to be used as "dotargs", e.g., the following three would be 
equivalent (except for issues around lazy evaluation):

# V1: current simple passing of dotargs
function(x, ...) {
    f(x, ...)
}

# V2: allow manipulation of dotargs using current language features, but 
syntax is ugly
function(x, ...) {
     dotargs <- list(...)
     do.call("f", c(list(x), dotargs))
}

# V3: proposed syntax for passing dotargs
function(x, ...) {
      dotargs <- list(...)
      f(x, ...=dotargs)  # a new syntax
}

This syntax in #3 would allow manipulation of dot-arguments, with a sweeter 
syntax for passing them than do.call() provides.

Where this might not fit neatly with the current semantics of the S 
language is that the "dotargs <- list(...)" would trigger evaluation of 
actual arguments.

-- Tony Plate

At Tuesday 03:28 PM 12/17/2002 -0500, Warnes, Gregory R wrote:


>I agree that it would be useful to be able to manipulate the contents of
><...>.
>Perhaps syntax like:
>
>         dots <- dotargs()  # equivalent to dots <- list(...)
>
>         val1 <- dotargs('arg1')
>
>to extract the contents of <...> and
>
>         dotargs('arg1') <- val1
>
>to modifiy the argument 'arg1' would do the trick.  Then one could do things
>like
>
>
>    myplot <- function(x,y, ...) {
>
>     plot(0:1, 0:1, type = "n", axes = FALSE)
>
>     result <-  <<do stuff with x,y>>
>
>     points(result, ...)
>
>     dotargs('pch') <- NA
>
>     axis(1, ...)
>     axis(2, ...)
>
>     dotargs('lwd') <- dotargs('xaxp') <- dotartgs('yaxp') <- NULL
>     title(...)
>    }
>
>
>-Greg
>
>
> > -----Original Message-----
> > From: Martin Maechler [mailto:maechler@stat.math.ethz.ch]
> > Sent: Tuesday, December 17, 2002 1:07 PM
> > To: R-devel@stat.math.ethz.ch
> > Subject: [Rd] Changing "..." inside a function: impossible? desirable?
> >
> >
> > This is was something like a request for your comments, thoughts
> > on the topic...
> >
> > Many of you will know that the "..." (aka \dots) argument is
> > very useful for passing ``further graphical parameters'',
> > but can be a pain when itself is passed to too many plotting
> > functions inside your own function.
> > An artificial example being
> >
> >   myplot <- function(x,y, ...) {
> >
> >    plot(0:1, 0:1, type = "n", axes = FALSE)
> >
> >    result <-  <<do stuff with x,y>>
> >
> >    points(result, ...)
> >    axis(1, ...)
> >    axis(2, ...)
> >    title(...)
> >   }
> >
> > It's clear that some things in "..." can be passed to title() and
> > some to axis(), etc.
> > Of course the above is really silly, but I have a situation
> > where I'd like to see if something, say, `myarg' is part of "..."
> > {piece of cake easy, see below} but then I want to  *eliminate*
> > it from "..." such that I can pass "..." down to other functions
> > which would want to see a `myarg' argument.
> >
> > Something like
> >
> > if("myarg" %in% (naml <- names(list(...)))) {
> >    ## ok, it's there, take it out
> >    marg <- list(...)$ marg
> >
> >    ## what I now would like is
> >
> >    ...  <-  unlist( list(...)["myarg" != naml] )
> > }
> >
> >
> > BTW: one relatively ugly workaround is to use the above *list*
> >      say  nlist <- list(...)["myarg" != naml]
> >      and do all subsequent call where I'd had "..." as
> >      do.call( <funname> ,  c(list( <<other args to funnname>>
> > ), nlist))
> > but this really obfuscates the code horrendously.
> >
> > PS:
> >     I know that using a  pars = list(.) argument instead of "..."
> >     is another alternative (that we have been using) as well,
> >     but lets assume this can't be done, because of
> > compatibility reasons.
> >
> > Martin Maechler <maechler@stat.math.ethz.ch>
>http://stat.ethz.ch/~maechler/
>Seminar fuer Statistik, ETH-Zentrum  LEO C16    Leonhardstr. 27
>ETH (Federal Inst. Technology)  8092 Zurich     SWITZERLAND
>phone: x-41-1-632-3408          fax: ...-1228                   <><
>
>______________________________________________
>R-devel@stat.math.ethz.ch mailing list
>http://www.stat.math.ethz.ch/mailman/listinfo/r-devel
>
>
>LEGAL NOTICE\ Unless expressly stated otherwise, this message is ... 
>[[dropped]]
>
>______________________________________________
>R-devel@stat.math.ethz.ch mailing list
>http://www.stat.math.ethz.ch/mailman/listinfo/r-devel