如何在 R 中测试 EOF 标志?

How to test for the EOF flag in R?

提问人: 提问时间:9/20/2008 最后编辑:Unheilig 更新时间:4/23/2015 访问量:5187

问:

如何在 R 中测试标志?EOF

例如:

f <- file(fname, "rb")
while (???) {
    a <- readBin(f, "int", n=1)
}
R 文件 -IO EOF

评论


答:

7赞 Ben Hoffstein 9/20/2008 #1

readLines 函数在到达 EOF 时将返回一个长度为零的值。

5赞 ars 7/30/2009 #2

尝试检查 readBin 返回的数据长度:

while (length(a <- readBin(f, 'int', n=1)) > 0) {
    # do something
}