Re: [Rd] Convenience function to get unevaluated ... function arguments

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Wed, 25 Jul 2012 15:59:34 -0700

On Jul 24, 2012, at 4:39 PM, Bert Gunter wrote:

> Folks:
>
> Herein is a suggestion for a little R convenience function mainly to
> obtain unevaluated ... function arguments. It arose from a query on
> R-help on how to get these arguments. The standard (I think) idiom to
> do this is via
>
> match.call(expand.dots=FALSE)$...
>
> However, Bill Dunlap pointed out that this repeats the argument
> matching of the function call and suggested a couple of alternatives
> that do not, one of which I've adapted as the following function,fun
> (I'll comment on naming in a second):
>
> fun <- as.list(substitute((...), env = parent.frame()))[-1]

I think instead:

fun <- function() as.list(substitute((...), env = parent.frame()))[-1]

-- 
David.

>
> Typical usage would be:
>
> f <- function(x, ...,y)fun()
>
> e.g.
>
>> f(x = 5,z=sin(a),y=3,stop("oh"),w=warning("Yikes"))
> $z
> sin(a)
>
> [[2]]
> stop("oh")
>
> $w
> warning("Yikes")
>
> It turns out that (surprisingly to me) the substitute idiom is faster
> than the match.call idiom, although the difference appears
> unimportant, since both are so fast. And it is a little slower when
> wrapped into a function, anyway -- I wasn't able to figure out a
> convenient way to wrap the match.call version into a function.
>
> The question is where -- if anywhere -- should this little one-liner
> go? Seems to me that there are 3 possibilities:
> 1. Nowhere. Unnecessary and trivial. An entirely reasonable response,
> imho; I leave it to guRus to make this judgment.
>
> 2. In with match.call(); in which case a name like match.dots would
> seem appropriate.
>
> 3. In with substitute(); in which case something like substituteDots
> to make the relationship clear might be appropriate.
>
> If R core or others do want to use this, I would be happy to write the
> line or two of additional documentation required (if no one else wants
> to).
>
> And to repeat... I know this is trivial, so no explanation or response
> is needed if it is decided to ignore it.
>
> Best,
> Bert
>
>
>
>
> --
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>
> Internal Contact Info:
> Phone: 467-7374
> Website:
> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
David Winsemius, MD Heritage Laboratories West Hartford, CT ______________________________________________ R-devel_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed 25 Jul 2012 - 23:13:38 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 27 Jul 2012 - 12:00:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive