是否可以在 R 中指定一个包含超过 1 个符号的注释字符?
例如,
read.table("data.dat", comment.char="//")
不会工作。
是否可以在 R 中指定一个包含超过 1 个符号的注释字符?
例如,
read.table("data.dat", comment.char="//")
不会工作。
我不认为你可以,但这里有一个解决方法。一个函数,它读取文件,使用 清理其行sub
,并将所有内容重新粘贴在一起,然后将其传递给read.table
:
my.read.table <- function(file, comment.char = "//", ...) {
clean.lines <- sub(paste0(comment.char, ".*"), "", readLines(file))
read.table(..., text = paste(clean.lines, collapse = "\n"))
}
测试:
file <- textConnection("3 4 //a
1 2")
my.read.table(file)
# V1 V2
# 1 3 4
# 2 1 2