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

From: Henrik Bengtsson <hb_at_stat.berkeley.edu>
Date: Fri, 01 Jun 2007 10:58:29 +0200

I use:

foo <- function(...) {
  args <- list(...);
  names(args);
}

/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. Received on Fri 01 Jun 2007 - 09:06:03 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 - 09:31:41 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.