From gregory_r_warnes@groton.pfizer.com  Tue Dec 17 22:33:02 2002
From: gregory_r_warnes@groton.pfizer.com (Warnes, Gregory R)
Date: Tue Dec 17 22:33:02 2002
Subject: [Rd] Changing "..." inside a function: impossible? desirable?
Message-ID: <D7A3CFD7825BD6119B880002A58F06C202F2C3AC@groexmb02.pfizer.com>


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]]



[Rd] Changing "..." inside a function: impossible? desirable?
Warnes, Gregory R