[R] Recovering object names when using the ... argument in a fn XXXX

Bert Gunter gunter.berton at gene.com
Fri Oct 18 19:07:36 CEST 2013


1. Always cc to the list unless it is truly a private offlist reply.
This is to get help from a wider audience, as may well be required
here. Translation: Take my "solution" with a grain of salt. It is
fragile at best.

2. I think ?match.call and ?deparse are what you're looking for:

f <- function(...){
  deparse(match.call())
}

> g(a,b,sqrt(c(1,2,5)))
[1] "a"                "b"                "sqrt(c(1, 2, 5))"

Cheers,
Bert




On Fri, Oct 18, 2013 at 9:36 AM, Dan Abner <dan.abner99 at gmail.com> wrote:
> Hi Bert,
>
> Thanks for your response. Please see example below:
>
>
> d1<-data.frame(x1=runif(100),x2=runif(100))
> d2<-data.frame(x3=runif(100),x4=runif(100))
> d3<-data.frame(x5=runif(100),x6=runif(100))
> set1 <- function(...,by){
>     df.name <<- list(...)
>     name1<<-names(list(...))
> }
>
> set1(d1,d2,d3)
>
> I need to be able to recover whatever input data frame names that the user
> passes to set1() (preferably in the character vector).
>
>> name1
> NULL
>
> Here is another possible call to the fn:
>
> set1(d1,d2)
>
>
>
>
>
>
> On Fri, Oct 18, 2013 at 12:26 PM, Bert Gunter <gunter.berton at gene.com>
> wrote:
>>
>> I'm not exactly sure what you mean by "names." Does the following meet
>> your needs?
>>
>> f <- function(...)names(list(...))
>>
>> > f(a=2,b=3)
>> [1] "a" "b"
>> > f(a=2,3)
>> [1] "a" ""
>>
>> If not, a reproducible example of what you want might be helpful.
>>
>> Cheers,
>> Bert
>>
>>
>>
>>
>> On Fri, Oct 18, 2013 at 9:05 AM, Dan Abner <dan.abner99 at gmail.com> wrote:
>> > Hi all,
>> >
>> > I am using the ... argument to parmeterize a user define fn to accept
>> > multiple input objects. I subsquently save all these data as a list.
>> > Question: what is the best way to recover or extract the original object
>> > names that were fed to the fn?
>> >
>> > Thanks,
>> >
>> > Dan
>> >
>> >         [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > R-help at r-project.org 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.
>>
>>
>>
>> --
>>
>> Bert Gunter
>> Genentech Nonclinical Biostatistics
>>
>> (650) 467-7374
>
>



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

(650) 467-7374



More information about the R-help mailing list