[BioC] evaluating a character string as a variable name in an ExpressionSet object

Saroj K Mohapatra smohapat at vbi.vt.edu
Fri Apr 17 03:28:25 CEST 2009


Hi Kavitha:

Are you looking for something like this:

> ls()
character(0)
> 
# I have a string called "reallyfunnyvariable"
> mystr = "reallyfunnyvariable"
 
# I want to convert this to a variable with the same name; I want it to be a list
eval(parse(text=paste(mystr,"=list()",sep="")))
 
# Now I have the variable
> ls()
[1] "mystr"               "reallyfunnyvariable"

# it is a list
> reallyfunnyvariable
list()

You have to be careful though while turning strings into variable, especially in the "batch" mode - what if the string is something like "plot"? 

You might want to add a clause for first checking if the variable exists, before assigning the variable name.

Best,

Saroj


----- Original Message -----
From: "Kavitha Venkatesan" <kavitha.venkatesan at gmail.com>
To: bioconductor at stat.math.ethz.ch
Sent: Thursday, April 16, 2009 5:58:44 PM GMT -05:00 US/Canada Eastern
Subject: [BioC] evaluating a character string as a variable name in an ExpressionSet object

I would like to know how to evaluate a character string as a variable name
in R. Specifically, I need to "compute" the variable name in the phenoData
slot of an ExpressionSet object.

> varLabels(sample.ExpressionSet)
[1] "sex"   "type"  "score"

Now I need to retrieve the factors sample.ExpressionSet$sex,
sample.ExpressionSet$type and sample.ExpressionSet$score in turn.
Furthermore, I need to be able to generalize my code so that I can retrieve
this factor for any phenodata variable in any given ExpressionSet object.

Clearly I cannot do something like

for (i in c(1:length(varLabels(sample.ExpressionSet)))
{
class_label <- varLabels(sample.ExpresionSet)[i]
class_label_factor <-  sample.ExpressionSet$class_label
}

Here class_label is interpreted as a character string by R, but I need for
it to be evaluated as a variable name. Seems straightforward, but I couldn't
figure it out...How can I do this? Thanks in advance for any help!

Kavitha

	[[alternative HTML version deleted]]

_______________________________________________
Bioconductor mailing list
Bioconductor at stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/bioconductor
Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor

-- 
Computational Biology
VBI @ Virginia Tech



More information about the Bioconductor mailing list