Re: [R] RE: Using a number as a name to access a list

From: Thomas Lumley <tlumley_at_u.washington.edu>
Date: Fri 11 Feb 2005 - 03:27:09 EST

On Thu, 10 Feb 2005, michael watson (IAH-C) wrote:

> The answer of course is parse()!

Nononono. If the answer is parse() you should usually rethink the question.

The answer is as.list(WHATEVERITWASCALLED)[[path]]

         -thomas

>
> Thank you and good night!
> M
>
> -----Original Message-----
> From: michael watson (IAH-C)
> Sent: 10 February 2005 13:36
> To: r-help@stat.math.ethz.ch
> Subject: Using a number as a name to access a list
>
>
> Hi
>
> Dumb question time again, for which I apologise.
>
> I have a variable that contains the following numerical text "04010".
> This is the name to access a list:
>
>> as.list(KEGGPATHID2NAME)$"04010"
> [1] "MAPK signaling pathway"
>
> Marvellous! Except I want to do that when "04010" is assigned to a
> variable called path and I can't figure out how to do it!
>
>> path <- "04010"
>>
>> # the original and best
>> as.list(KEGGPATHID2NAME)$"04010"
> [1] "MAPK signaling pathway"
>>
>> # clearly this doesn't, and shouldn't, work
>> as.list(KEGGPATHID2NAME)$path
> NULL
>>
>> # this produces a string...
>> eval(paste("as.list(KEGGPATHID2NAME)$",path,sep=''))
> [1] "as.list(KEGGPATHID2NAME)$04010"
>>
>> # as does this
>> eval(paste('as.list(KEGGPATHID2NAME)$"',path,'"',sep=''))
> [1] "as.list(KEGGPATHID2NAME)$\"04010\""
>>
>
> Whats really annoying is that when everyone mails me the answer, I'm
> going to have known how obvious it is.... Thanks in advance
>
> Mick
> Village Idiot
>
> ______________________________________________
> 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
>

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley@u.washington.edu	University of Washington, Seattle

______________________________________________
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 Received on Fri Feb 11 03:00:51 2005

This archive was generated by hypermail 2.1.8 : Fri 11 Feb 2005 - 03:21:53 EST