最终记录中缺少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'

谢谢。 MM

name1006 回答:最终记录中缺少CRLF,导致在读取数据集中出现问题

我设法重现您的问题的唯一方法是当我使用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)
本文链接:https://www.f2er.com/3161589.html

大家都在问