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

Warnes, Gregory gregory.warnes at novartis.com
Thu Jul 26 16:52:54 CEST 2012


I'll be glad to add it to the gtools package if it doesn't (immediately) go into one of the core packages.

Sent from my iPhone

On Jul 26, 2012, at 7:35 AM, "Bert Gunter" <gunter.berton at gene.com> wrote:

> Indeed!
> 
> -- Bert
> 
> On Wed, Jul 25, 2012 at 3:59 PM, David Winsemius <dwinsemius at comcast.net> wrote:
>> 
>> 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
>> 
> 
> 
> 
> -- 
> 
> 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



More information about the R-devel mailing list