首页 > 解决方案 > 最终记录中缺少 CRLF,导致读取数据集出现问题

问题描述

我有两个数据集,其中包含最后一行缺少 CRLF 的数据行。我必须将其添加到文件中才能读入它们。有没有一种方法可以在不修改这些文件的情况下读入?

最终记录之一如下所示:

surface NewYork Ave.             1259 1290 no final carriage return 
                                                at end of record

警告信息:

In readLines(file, n = thisblock) : incomplete final line found on 
                                     roadways.dat'

谢谢。毫米

标签: r

解决方案


我设法重现您的问题的唯一方法是使用 win unicode 文件encoding = "UCS-2LE"。解决问题的几种方法,如果它产生所需的输出,则警告您对其进行测试。在大多数情况下,这是一个警告,您可以使用可用的开关来抑制它。

# set the warning FALSE (Assuming it is just a warning with no effect)
data <- readLines(con <- file("your_file", encoding = "UCS-2LE"), warn = FALSE, n=-1)
# Or see if other alternative encoding can solve your problem 
A <- readLines(con <- file("your_file", encoding = "UTF-8"), n=-1)

推荐阅读