[BioC] Problems substituting slot name with string variable

James W. MacDonald jmacdon at med.umich.edu
Tue Jul 6 18:49:16 CEST 2010


Hi Edwin,

On 7/6/2010 11:02 AM, Edwin Groot 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,
> + repData$size, totalGenes-repData$size,
> + sizeData[`dataset`,], lower.tail = FALSE);
> probTable$`dataset`<- probVector }
>
> 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!
>
> 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.

This is more suited to R-help, as there is no BioC component that I can 
discern.

However, if you are simply trying to get the preceding column, why don't 
you just convert to numeric rather than trying to do parsing magic?

for(i in rownames(sizeData)){
ind <- which(names(repData) == i) - 1
probVector <- phyper(repData[,ind],
repData$size, totalGenes-repData$size,
sizeData[i,], lower.tail=FALSE)
probTable[,i] <- probVector
}

Best,

Jim




Best,

Jim



>
> TIA for helping me out of a mental block,
> Edwin
> p.s. R 2.11.1 i486 linux-gnu; Bioc err... 2.6

-- 
James W. MacDonald, M.S.
Biostatistician
Douglas Lab
University of Michigan
Department of Human Genetics
5912 Buhl
1241 E. Catherine St.
Ann Arbor MI 48109-5618
734-615-7826
**********************************************************
Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues 



More information about the Bioconductor mailing list