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

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri, 01 Jun 2007 14:34:27 +0100 (BST)

How about

foo <- function(...)
{

    m <- as.list(match.call(expand.dots=TRUE))[-1]     nm <- names(m)
    for(i in seq_along(m)) if(!nchar(nm[i])) nm[i] <- deparse(m[[i]])     nm
}

Such things are hard to do from R level, hence the use of match.call to do it at C level.

On Fri, 1 Jun 2007, Mike Meredith wrote:

>
>
> Thanks, Henrik, but 'foo' doesn't do what I want:
>
> x <- "some stuff"
> second <- "more stuff"
>
> foo(first=x, second)
> [1] "first" ""
>
> Brian's right:
>> ...he wants the argument name if there is one otherwise the
>> deparsed argument value, but clarification would be helpful.
>
> The function using this compares estimates of animal densities, CIs, etc
> using different models, with one object containing the results of one model.
> It extracts key results and AIC from these objects and does a summary
> matrix, with lowest AIC at the top, so the row names need to reflect the
> model used.
>
> If the object name is sufficiently explanatory -- eg. point.est.hazardRate
> -- then the deparsed argument value is fine as row name. But we need the
> option to be more specific if necessary, eg. with "halfNormal=x1,
> hazardRate=x2". Just like 'rbind', in fact.
>
> Thanks, Mike
>

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

______________________________________________
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.
Received on Fri 01 Jun 2007 - 13:44:31 GMT

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 01 Jun 2007 - 15:31:21 GMT.

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