在R脚本中正确使用list.files

在R脚本中正确使用list.files,r,error-handling,execution,R,Error Handling,Execution,我正在写一个R脚本并使用这个函数 filenames <- list.files(opt$bamfolder, pattern = "\\.bam$") 但是当我运行它时,我得到了这个错误 Error: unexpected input in: filenames <- list.files(opt$bamfolder, pattern = "\" Execution halted 有人知道我做错了什么吗?试试pattern=\\.bam$或pattern=[.]bam$。我不

我正在写一个R脚本并使用这个函数

filenames <- list.files(opt$bamfolder, pattern = "\\.bam$")
但是当我运行它时,我得到了这个错误

Error: unexpected input in:
 filenames <- list.files(opt$bamfolder, pattern = "\"
Execution halted

有人知道我做错了什么吗?

试试pattern=\\.bam$或pattern=[.]bam$。我不知道为什么这对你不起作用,但如果你只是想列出所有扩展名为.bam的文件,pattern=*.bam也应该起作用。什么是opt$bamfolder?除非您有一个包含文件路径的结构,否则它似乎不会返回文件路径。如果是数据帧,请检查它是否不是一个因素column@RichardScrivenopt$bamfolder之所以存在,是因为我在脚本前面使用了getopt并为bamfiles设置了一个变量。错误消息提示一个奇怪的字符,可能是非打印字符。你用的是什么编辑器?它是否允许您对输入进行消毒?