r - 为什么 fread 在 Linux 上可以正常读取 URL,但在 Windows(1.9.3 之前)上却不行?

标签 r data.table

我正在尝试从网上读取 csv。当我运行时

library(data.table)
rawfile<-fread("http://www.pjm.com/pub/account/genoutages/20140116_genout.csv",stringsAsFactors=FALSE,skip=2)
rawfile

我明白

Empty data.table (0 rows) of 2 cols: File Posted on 16-Jan-2014 04:00,V2

但是如果我先将文件下载到我的计算机上,然后执行

rawfile<-fread("c:\\temp\\20140116_genout.csv",stringsAsFactors=FALSE,skip=2)
rawfile

然后我得到了我期望的输出。

我知道这很容易解决,因为我只是想看看这是否是一个错误,或者是否存在一些我无法理解的细微差别。

最佳答案

更新 2014 年 9 月:现已在 v1.9.3 中修复

URLs now work on Windows. R's download.file() converts \r\n to \r\r\n on Windows. Now avoided by downloading in binary mode. Thanks to Steve Miller and Dean MacGregor for reporting, #492.


感谢您的报告。当我刚刚在 Linux 上尝试时,它对我来说效果很好。请参阅下面的输出。

?fread 确认支持 URL:“为了方便起见,文件名输入通过 path.expand 传递,并且可能是以 http://或 file://开头的 URL。”

鉴于评论,这似乎是 Windows 独有的问题。在这里提出了一个错误:
#5288 fread reads URLs on Linux but not Windows?

这是在 Linux 上运行的输出:

fread("http://www.pjm.com/pub/account/genoutages/20140116_genout.csv",stringsAsFactors=FALSE,skip=2) trying URL 'http://www.pjm.com/pub/account/genoutages/20140116_genout.csv' Content type 'application/octet-stream' length 2767 bytes opened URL ================================================== downloaded 2767 bytes

         Date Forecasted Generation Outage Western Region Other Regions
 1: 1/17/2014                         1543            374          1169
 2: 1/18/2014                         1520            374          1146
 3: 1/19/2014                         1520            374          1146
 4: 1/20/2014                         1520            374          1146
 5: 1/21/2014                         1520            374          1146
 6: 1/22/2014                         1520            374          1146
 7: 1/23/2014                         1506            374          1132
 .. snip

关于r - 为什么 fread 在 Linux 上可以正常读取 URL,但在 Windows(1.9.3 之前)上却不行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21173293/

相关文章:

r data.table 条件和引用/从另一个单独的 data.table 执行查找

regex - 如何在 R 中的字符串中搜索美元符号?

r - 从 "package::function"形式的字符串中获取函数

r - 根据条件创建累积每周平均值的 Date.table 解决方案

r - 获取data.table中上一组的最后一行

r - 与组内或外部变量中较早实例的差异

在 Debian 中使用 data.table 运行脚本时 RStudio/R 崩溃

r - 从 R 中的三个向量创建一个命名列表的列表

R Shiny 的 future : plan(multiprocess)/plan(multicore) + Kill long running process

r - 在函数调用中使用变量时,MASS 包中的 glm.nb 链接函数不起作用?