[R] Extracting the name of an object into a character string and vice versa
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Dec 12 14:41:48 CET 2008
Its a FAQ:
http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-turn-a-string-into-a-variable_003f
On Fri, Dec 12, 2008 at 8:30 AM, Philip Whittall
<Philip.whittall at detica.com> wrote:
>
> I am still struggling to map a character string to an object name and
> vice versa in R.
> I thought the as.name() function might work, but observe the following
> behaviour ...
>
>> attach(warpbreaks)
>> levels(tension)
> [1] "L" "M" "H"
>> levels(as.name("tension"))
> NULL
>> objectname<-as.name("tension")
>> objectname
> tension
>> levels(objectname)
> NULL
>
> So even though it sets up a symbol, this symbol isn't recognised as an
> object name by functions such as levels().
>
> I need 2 functions, call them A and B such that A("tension") yields the
> object name tension which is recognised by functions and
> B(tension) yields the character result "tension".
>
> Any suggestions would be greatly appreciated,
>
> Philip
>
>
>
>
>
>
>
>
>
> This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately.
> Statements of intent shall only become binding when confirmed in hard copy by an authorised signatory. The contents of this email may relate to dealings with other companies within the Detica Group plc group of companies.
>
> Detica Limited is registered in England under No: 1337451.
>
> Registered offices: Surrey Research Park, Guildford, Surrey, GU2 7YP, England.
>
>
>
> [[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