[BioC] Problems substituting slot name with string variable

Edwin Groot edwin.groot at biologie.uni-freiburg.de
Tue Jul 6 17:37:10 CEST 2010


On Tue, 6 Jul 2010 11:10:36 -0400
 Sean Davis <sdavis2 at mail.nih.gov> wrote:
> On Tue, Jul 6, 2010 at 11:02 AM, Edwin Groot <
> edwin.groot at biologie.uni-freiburg.de> wrote:
> 
> > Hello all,
> > I am trying to repeat a hypergeometric test 40 times by putting it
> in a
> > loop, but I am missing something as it does not work.
> > How do I substitute a slot name with a string variable?
> >
> > Here is the code so far:
> > > probTable <- data.frame(row.names=rownames(repData))
> > > for (dataset in rownames(sizeData)) {
> > + probVector <- phyper(repData$`dataset`-1,
> >
> 
> Hi, Edwin.
> 
> repData[,dataset]
> 
> 
> > + repData$size, totalGenes-repData$size,
> > + sizeData[`dataset`,], lower.tail = FALSE);
> >
> 
> sizeData[dataset,]
> 
> > probTable$`dataset` <- probVector }
> >
> >
> probTable[,dataset]
> 
> 
> > Error in `$<-.data.frame`(`*tmp*`, "dataset", value = numeric(0)) :
> >  replacement has 0 rows, data has 492
> >
> > The point here is that backticking is not working for me:
> > repData$`dataset` returns NULL.
> > I tried variations on single quotes, substitute(), eval() and
> evalq(),
> > but none work!
> >
> 
> You might benefit from a quick primer on R subsetting.  The Intro to
> R
> manual is one place to start.
> 
> Sean
> 

Thanks Sean, it worked like a charm!
Of course I know [,]. It just did not click in at the time.
I think I got mixed up with BASH scripting and made things overly
complicated.
I'll give this PDF R manual a closer read...

Onward to functions!
Edwin
-- 
> 
> 
> >
> > FYI the sizeData object is a data frame of 40 rows. The repData
> object
> > is a data frame of 492 rows and 41 columns. The names of 40 of the
> > columns are identical to the names of the 40 rows in sizeData.
> >
> > TIA for helping me out of a mental block,
> > Edwin
> > p.s. R 2.11.1 i486 linux-gnu; Bioc err... 2.6
> > --
> > Dr. Edwin Groot, postdoctoral associate
> > AG Laux
> > Institut fuer Biologie III
> > Schaenzlestr. 1
> > 79104 Freiburg, Deutschland
> > +49 761-2032945
> >
> > _______________________________________________
> > 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
> >

Dr. Edwin Groot, postdoctoral associate
AG Laux
Institut fuer Biologie III
Schaenzlestr. 1
79104 Freiburg, Deutschland
+49 761-2032945



More information about the Bioconductor mailing list