Re: [R] Object name and Strings?

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Tue 18 Jul 2006 - 19:26:22 EST

On Tue, 18 Jul 2006, Stéphane Cruveiller wrote:

> Thanks for your answer.
>
> Here is what I am trying to do.
> I have a list which is called MyList. I would like to get only the "name"
> of this object as a simple characters string. i.e. Is there a function in R
> which is able
> to give:
>
> > name<-fun(Mylist)
> > name
> "MyList"

myfun <- function(x) deparse(substitute(x))

That's how to find the name (if it was a name) given as a function argument.

>
>
> thanks in advance,
>
> Stéphane.
>
>
>
> Prof Brian Ripley a écrit :
> > On Tue, 18 Jul 2006, Stéphane Cruveiller wrote:
> >
> >
> > > Hi all,
> > >
> > > Is there a simple way to convert an object name to a characters string?
> > >
> >
> > Yes, as.character, as in
> >
> >
> > > x <- as.name("foo")
> > > x
> > >
> > foo
> >
> > > as.character(x)
> > >
> > [1] "foo"
> >
> > However, I suspect you are not using the words in their technical sense
> > (a name is a synonym for a symbol in R), so if this is not the answer,
> > please give us an example of what you are trying to do (which might be
> > deparse).

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


______________________________________________ R-help@stat.math.ethz.ch 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.

Received on Tue Jul 18 19:30:29 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 18 Jul 2006 - 20:17:25 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.