[R] deparseDots to get names of all arguments?

Bert Gunter bgunter.4567 at gmail.com
Wed Feb 21 01:01:27 CET 2018


If you want to avoid the inefficiency and memory overhead of first
constructing the list and work directly on the language, then I think
?match.call is the tool you want. e.g.


> f <- function(...){
    z <- as.list(match.call())[-1]
    vapply(z,deparse,"a")
 }

> a <- 1
> b <- 2

> f(a,b)
[1] "a" "b"

I am sure that there are packages that may do this more elegantly and
perhaps reliably, though.

Cheers,
Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Tue, Feb 20, 2018 at 2:47 PM, Rolf Turner <r.turner at auckland.ac.nz>
wrote:

> On 21/02/18 11:36, Spencer Graves wrote:
>
>> Hi, All:
>>
>>
>>        How can I get the names of all the arguments in dots(...)?
>>
>>
>>        I'm able to get the name of the first argument but not the second:
>>
>>
>>
>> deparseDots <- function(...){
>>    deparse(substitute(...))
>> }
>> a <- 1
>> b <- 2
>> deparseDots(a, b)
>> [1] "a"
>>
>>  >        I'd like to get c('a', 'b').
>>
>
> Does
>
>     names(list(...))
>
> do what you want?
>
> cheers,
>
> Rolf
>
> --
> Technical Editor ANZJS
> Department of Statistics
> University of Auckland
> Phone: +64-9-373-7599 ext. 88276
>
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posti
> ng-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list