2017-04-26 35 views
-1

我正试图下载一个大型的纽约出租车数据库,公开可在NYC TLC websiteFread不寻常的行结束导致错误

library(data.table) 
feb14 <- fread('https://s3.amazonaws.com/nyc-tlc/trip+data/yellow_tripdata_2014-02.csv', header = T) 

执行上述代码成功下载数据(需要几分钟),但由于内部错误而无法解析。我也尝试删除header = T

有没有解决方法来处理fread中的“不寻常的行结束”?

Error in fread("https://s3.amazonaws.com/nyc-tlc/trip+data/yellow_tripdata_2014-02.csv", : 
    Internal error. No eol2 immediately before line 3 after sep detection. 
In addition: Warning message: 
In fread("https://s3.amazonaws.com/nyc-tlc/trip+data/yellow_tripdata_2014-02.csv", : 
    Detected eol as \n\r, a highly unusual line ending. According to Wikipedia the Acorn BBC used this. If it is intended that the first column on the next row is a character column where the first character of the field value is \r (why?) then the first column should start with a quote (i.e. 'protected'). Proceeding with attempt to read the file. 
+0

我希望我知道几分钟将是20和文件大小是> 2演出:)。无论如何,一旦文件被读取,我就会查看它。 – Drj

+2

顺便说一句,这里最好[mcve]。在这种情况下,最小可能意味着做一个不是2 GB的例子;并且可重复使用意味着不会使用可能在某个时候断开的链接... – Frank

回答

0

像read.csv有时其他选项/函数read.table 可以行为不同...所以你总是可以试试。 (也许源代码告诉你为什么,没有看过)。

另一种选择是使用readLines()来读取这样的文件。据我所知,这里没有解析/格式化。所以,就我所知,这是读取文件的最基本的方式。

最后,快速修复:在fread中使用选项'skip = ...',或者通过说'nrows = ...'。

+0

'...'做了什么以及应该跳过什么? –

+0

点的意思是一个值,你可以输入你自己的:) – zwep

+0

我理解这意味着我应该跳到第3行? –

0

有一些与fread腥。 data.table是更快,更高性能的阅读大文件,但在这种情况下,行为并不是最佳的。您可能要提高对github

我能够重现上下载的文件的问题,即使有nrows = 5甚至与nrows = 1但只有坚持原始文件这个问题。如果我复制粘贴前几行然后尝试,问题就没有了。如果我直接从网上阅读小nrows,问题也会消失。这甚至不是encoding问题,因此我建议提出问题。

我试着用read.csv100,000行读取文件没有问题,并在6秒以下。

feb14_2 <- read.csv("https://s3.amazonaws.com/nyc-tlc/trip+data/yellow_tripdata_2014-02.csv", header = T, nrows = 100000) 

header = T是多余的参数,因此不会有所作为的fread但需要read.csv