简体   繁体   English

file(file,“ rt”)R参数错误

[英]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.

相关问题 文件错误(文件“ rt”) - Error in file(file, “rt”) 文件错误(文件,“rt”):无法在 r 中打开连接 - Error in file(file, “rt”) : cannot open the connection in r R闪亮:文件错误(文件,“ rt”):无效的“描述”参数 - R shiny: Error in file(file, “rt”) : invalid 'description' argument 无法将csv读取到R Markdown中:文件错误(文件,“ rt”) - Cannot read csv into R Markdown: Error in file(file, “rt”) 如何在R的函数中使用字符串? (文件,rt错误) - How do I use strings in functions for R ? (file,rt error) 我正在尝试在R中编织Word文档,但是文件(文件,“ rt”)出现错误? - I'm trying to knit a Word doc in R but I get an error in file (file,“rt”)? R-saemixData函数在函数环境中找不到数据“文件错误(文件,“ rt”):无法打开连接” - R - saemixData function do not find data in a function environment “Error in file(file, ”rt“) : cannot open the connection” 文件中的错误(文件,“rt”):即使设置正确的路径,也无法在 r 中打开连接 - Error in file(file, "rt") : cannot open the connection in r even after setting right path 文件中的错误(文件,“rt”):无法打开连接另外:警告消息:在文件(文件,“rt”)中:无法打开文件 - Error in file(file, “rt”) : cannot open the connection In addition: Warning message: In file(file, “rt”) : cannot open file 在文件(文件,“ rt”)中出现错误:无法打开连接 - Getting Error in file(file, “rt”) : cannot open the connection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM