错误提示我似乎不存在NA / NaN / Inf值。 hclustfun(distc)中的错误:外部函数调用(参数11)中的NA / NaN / Inf

时间:2018-10-31 10:48:34

标签: r nan na gplots

我有一个看起来像这样的文件:

Taxa,D0,D1,...
1,0,10,...
20,0,0,...
...

文件位于此处:https://www.dropbox.com/s/lvtxztz3kypnxre/Taxa_Conf.csv?dl=0

当我通过

运行脚本时
$CONCOCT/scripts/ConfPlot.R -c Taxa_Conf.csv -o Taxa_Conf.pdf

我收到以下错误:

Error in hclustfun(distc) : NA/NaN/Inf in foreign function call (arg 11)
Calls: heatmap.2 -> hclustfun
Execution halted

其中ConfPlot.R看起来像

#!/usr/bin/Rscript

#load libraries
library(gplots)
library(getopt)

spec = matrix(c('verbose','v',0,"logical",'help','h',0,"logical",'confile','c',1,"character",'ofile','o',1,"character"),byrow=TRUE,ncol=4)

opt=getopt(spec)

if( !is.null(opt$help)) {
cat(getopt(spec, usage=TRUE)); 
q(status=1);
}

confFile <- opt$confile

Conf <- read.csv(confFile,header=TRUE,row.names=1)
Conf.t <- t(Conf)
ConfP <- Conf.t/rowSums(Conf.t)

crp <- colorRampPalette(c("blue","red","orange","yellow"))(100)

pdf(opt$ofile)

heatmap.2 (as.matrix(t(ConfP)),col=crp,trace="none",dendrogram="none",Rowv=FALSE,lwid = c(1.25,4.5),lhei = c(1.25,4.5),cexRow=0.5)

dev.off()

阅读Error while creating heatmaps - NA/NaN/Inf in foreign function call (arg 11)后,我尝试了

> a=read.csv("/home/mathed/Simulation/custom_desman/1/Strains/Simulation/Metabat/Taxa_Conf.csv",header=TRUE,row.names=1)
> any(is.na(a))
[1] FALSE

似乎没有NA值。 ConfPlot.R适用于我的其他文件。 问题是什么??似乎没有任何na,nan或inf值。 预先谢谢你

1 个答案:

答案 0 :(得分:1)

选中此行:

ConfP <- Conf.t/rowSums(Conf.t)

必须从本质上进行除以零的评估:

> 0/0
[1] NaN

> 1/0
[1] Inf