YuanTian1991 / ChAMP

19 stars 22 forks source link

Avoid error from rowMeans() if there is only one DMP #21

Open mcol opened 2 years ago

mcol commented 2 years ago

When running champ.DMP(), if there is only one differentially expressed probe, the following fails:

avg <-  cbind(rowMeans(beta[com.idx,which(pheno==Compare[[i]][1])]),
              rowMeans(beta[com.idx,which(pheno==Compare[[i]][2])]))

because com.idx has length 1, and beta[com.idx,which(pheno==Compare[[i]][1])] instead of a matrix becomes a vector, over which cannot be computed row names. By adding drop=FALSE, we can make it return a matrix with one row, and the operation works.

In the patch I've also removing the use of which() as it seems unnecessary. The only case where it would make a difference is if pheno or Compare contain NAs, but I don't know if that is actually possible. In case, I can put the 'which()' back.

robinjugas commented 10 months ago

Thanks @mcol mcol, this helped me.