[R] colname of ... arguments

Duncan Murdoch murdoch at stats.uwo.ca
Thu Mar 11 13:00:57 CET 2010


ManInMoon wrote:
> That is quite helpful David
>
> niceplot<-function(...) {
>  parms=list(...)
>  for (x in parms) {
>  xname <- paste(deparse(substitute(x), 500), collapse = "\n")
>    cat(xname)
>  }
> }
>
>   
>> GreenEyes=c(1,2,3,4)
>> niceplot(GreenEyes)
>>     
> c(1, 2, 3, 4)
>   

>
> BUT what I want is:
>  > GreenEyes=c(1,2,3,4)
>   
>> niceplot(GreenEyes)
>>     
> "GreenEyes"
>   

That is deparse(substitute(...)), e.g.

 > f <- function(...) deparse(substitute(...))
 > f(GreenEyes)
[1] "GreenEyes"


Duncan Murdoch

>
> I will use the vector for plotting too, but I need it's name to produce a
> legend automatically
>
>
>
>
> On 10 March 2010 23:32, David Scott-6 [via R] <
> ml-node+1588213-620034400-180445 at n4.nabble.com<ml-node%2B1588213-620034400-180445 at n4.nabble.com>
>   
>> wrote:
>>     
>
>   
>> ManInMoon wrote:
>>
>>     
>>> I have writtn a function where I pass a variable number of arguments.
>>>
>>> I They are vectors and I can manipulate them, but I need to get hold of
>>>       
>> the
>>     
>>> name for a legend.
>>>
>>> niceplot<-function(...) {
>>>    parms=list(...)
>>>
>>>   for (x in parms) {
>>>     DoSomethingWith(x)
>>>   }
>>>
>>> }
>>>
>>> BUT how how can I get something like namestring(...) of nameofvector(x)?
>>>       
>> I use the following syntax to get the name of a data object to use in a
>> title, label or whatever.
>>
>> xname <- paste(deparse(substitute(x), 500), collapse = "\n")
>>
>> This is taken from hist.default so at least has some provenance as an
>> appropriate method.
>>
>> David Scott
>>
>> --
>> _________________________________________________________________
>> David Scott Department of Statistics
>>                 The University of Auckland, PB 92019
>>                 Auckland 1142,    NEW ZEALAND
>> Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
>> Email: [hidden email]<http://n4.nabble.com/user/SendEmail.jtp?type=node&node=1588213&i=0>,
>>  Fax: +64 9 373 7018
>>
>> Director of Consulting, Department of Statistics
>>
>> ______________________________________________
>> [hidden email]<http://n4.nabble.com/user/SendEmail.jtp?type=node&node=1588213&i=1>mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>> ------------------------------
>>  View message @
>> http://n4.nabble.com/colname-of-arguments-tp1588146p1588213.html
>> To unsubscribe from colname of ... arguments, click here< (link removed) ==>.
>>
>>
>>
>>     
>
>



More information about the R-help mailing list