[R] deparseDots to get names of all arguments?
Bert Gunter
bgunter.4567 at gmail.com
Wed Feb 21 01:17:48 CET 2018
Duncan et.al:
Referring to my previous suggestion for f:
> f(log(x),x^2)
[1] "log(x)" "x^2"
Is this not what you want?
Cheers,
Bert
On Tue, Feb 20, 2018 at 4:00 PM, Duncan Murdoch <murdoch.duncan at gmail.com>
wrote:
> On 20/02/2018 5:47 PM, Rolf Turner 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?
>>
>
> No, that does what he asked for, not what he wants :-). Spencer, you want
> to deparse all of the expressions in ..., not their names.
>
> I think base R doesn't have a way to do this (but I may be wrong). You
> can do it using some the rlang package. For example, this seems to work:
>
> deparseDots <- function(...) {
> unname(sapply(rlang::exprs(...), deparse))
> }
>
> Duncan Murdoch
>
>
> ______________________________________________
> 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