[R] colname of ... arguments

Greg Snow Greg.Snow at imail.org
Thu Mar 11 15:40:57 CET 2010


In the following code:

> y <- 1
> niceplot( x=y )

Do you want "x", "y", or 1?

1 is just the value, which you had already.  If you want "y" then the deparse(substitute()) approach gives that to you as others have said.  But if you want "x", then you want to look at the names of the dots list, e.g.:

> tmp <- function(...) print(names(list(...)))
> tmp(x=1, y=2)
[1] "x" "y"

If you want something else, then a better description/example may help.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of ManInMoon
> Sent: Thursday, March 11, 2010 1:34 AM
> To: r-help at r-project.org
> Subject: Re: [R] colname of ... arguments
> 
> 
> David,
> 
> That's useful to highlight my problem.
> If instead of e="e" we use a vector like GreenEyes:
> 
> > GreenEyes=c(1,2,3,4)
> > niceplot(GreenEyes)
> 1 2 3 4
> >
> 
> What I want is niceplot to print "GreenEyes" bot 1 2 3 4
> 
> I want this so I can use it in a legend without having to type in
> "GreenEyes"...
> 
> 
> On 10 March 2010 23:32, David Winsemius [via R] <
> ml-node+1588214-2107833523-180445 at n4.nabble.com<ml-node%2B1588214-
> 2107833523-180445 at n4.nabble.com>
> > wrote:
> 
> > I think you need to provide a richer example:
> >
> > niceplot<-function(...) {
> >    parms=list(...)
> >
> >   for (x in parms) {
> >     cat(x)
> >   }
> > }
> >  > e="e"
> >
> >  > niceplot(e)
> > e
> >
> > On Mar 10, 2010, at 5:21 PM, 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)?
> > > --
> > > View this message in context:
> > http://n4.nabble.com/colname-of-arguments-tp1588146p1588146.html
> > > Sent from the R help mailing list archive at Nabble.com.
> > >
> > > ______________________________________________
> > > [hidden
> email]<http://n4.nabble.com/user/SendEmail.jtp?type=node&node=1588214&i
> =0>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.
> >
> > ______________________________________________
> > [hidden
> email]<http://n4.nabble.com/user/SendEmail.jtp?type=node&node=1588214&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-tp1588146p1588214.html
> > To unsubscribe from colname of ... arguments, click here< (link
> removed) ==>.
> >
> >
> >
> 
> --
> View this message in context: http://n4.nabble.com/colname-of-
> arguments-tp1588146p1588605.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> 	[[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.



More information about the R-help mailing list