[R] Getting names of objects passed with "..."

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Jun 1 11:11:45 CEST 2007


On Fri, 1 Jun 2007, Henrik Bengtsson wrote:

> I use:
>
> foo <- function(...) {
>  args <- list(...);
>  names(args);
> }

But that does not do what was asked: it gets the argument names, not the 
object names.  (Did you actually try it?)  It looks from the example that 
he wants the argument name if there is one otherwise the 
deparsed argument value, but clarification would be helpful.

>
> /Henrik
>
> On 6/1/07, Mike Meredith <mmeredith at wcs.org> wrote:
>>
>> Is there a tidy way to get the names of objects passed to a function via the
>> "..." argument?
>>
>> rbind/cbind does what I want:
>>
>> test.func1 <- function(...) {
>>    nms <- rownames(rbind(..., deparse.level=1))
>>    print(nms)
>> }
>>
>> x <- "some stuff"
>> second <- "more stuff"
>> test.func1(first=x, second)
>> [1] "first"  "second"
>>
>> The usual 'deparse(substitute())' doesn't do it:
>>
>> test.func2 <- function(...) {
>>    nms <- deparse(substitute(...))
>>    print(nms)
>> }
>> test.func2(first=x, second)
>> [1] "x"
>>
>> I'm using "nms <- rownames(rbind(...))" as a workaround, which works, but
>> there must be a neater way!
>>
>> rbind/cbind are .Internal, so I can't pinch code from there.
>>
>> Thanks,  Mike.
>>
>> --
>> View this message in context: http://www.nabble.com/Getting-names-of-objects-passed-with-%22...%22-tf3850318.html#a10906614
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list