[英]Error in file(file, “rt”) R arguments
i am using below RScript. 我正在使用以下RScript。
/usr/local/bin/R CMD BATCH --slave '--args 51102' coverage_db/src/main/scripts/R_ExonsPlots.R
R Script as follows R脚本如下
args<-commandArgs(TRUE)
gname = as.numeric(args[1])
sample_data = read.table(Sys.glob("/NGS_STORE/ARCHIVE2/Cov_InputBed_Repository/*gname*"),sep="\t",header=FALSE,stringsAsFactors=FALSE)
colnames(sample_data)=c("chr","start","end","gene","avg_depth")
Error 错误
Error in file(file, "rt") : invalid 'description' argument
It worked fine without "arguments" but could not get what the error is 它在没有“参数”的情况下工作正常,但是无法得到错误所在
The error results from read.table
because multiple filenames are returned by the Sys.glob
. 该错误是由于read.table
导致的,因为Sys.glob
返回了多个文件名。 In this case, Sys.glob
will return a vector of characters, one for each file name matching the wildcard. 在这种情况下, Sys.glob
将返回一个字符向量,每个与通配符匹配的文件名一个。 Most likely, this problem is triggered by the other problem where the value for gname is actually not used since "/NGS_STORE/ARCHIVE2/Cov_InputBed_Repository/*gname*"
is just a string (characters). 此问题很可能是由另一个问题触发的,因为"/NGS_STORE/ARCHIVE2/Cov_InputBed_Repository/*gname*"
只是一个字符串(字符),因此实际上未使用gname的值。 To fix both: 要解决这两个问题:
args<-commandArgs(TRUE)
gname = as.numeric(args[1])
files = Sys.glob(paste0("/NGS_STORE/ARCHIVE2/Cov_InputBed_Repository/*",gname,"*"))
if (!is.na(files[1])) {
sample_data = data.frame()
for (afile in files) {
sample_data = rbind(sample_data, read.table(afile, sep="\t", header=FALSE,
stringsAsFactors=FALSE))
}
colnames(sample_data)=c("chr","start","end","gene","avg_depth")
}
Here, I'm assuming that if there are multiple files satisfying the glob, you want to combine them by rows (ie, they have the same number of columns). 在这里,我假设如果有多个文件满足您的要求,那么您希望按行将它们合并(即,它们具有相同的列数)。 Obviously, you can combine them by columns, ignore all but the first, etc. 显然,您可以按列组合它们,忽略除第一个以外的所有内容,等等。
Note that if there are no matches for the glob, then it will return NA
. 请注意,如果该glob没有匹配项,则它将返回NA
。 That is why we need to check for NA
before calling read.table
. 这就是为什么我们需要在调用read.table
之前检查NA
原因。 Otherwise, you will get the read.table
error Error in file(file, "rt") : cannot open the connection
. 否则,您将得到read.table
错误Error in file(file, "rt") : cannot open the connection
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.