簡體   English   中英

嘗試在.csv文件上使用fread(),但收到內部錯誤“ ch> eof”

[英]trying to use fread() on .csv file but getting internal error “ch>eof”

我從恐懼中得到一個錯誤:

內部錯誤:檢測到eol時ch> eof

嘗試使用R 3.2.0讀取從https服務器下載的csv文件時。 我在Github上找到了一些相關的東西, https://github.com/Rdatatable/data.table/blob/master/src/fread.c ,但根本不知道如何使用它。 謝謝你的幫助。

添加的信息:數據是從此處下載的:

fileURL <- "https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06pid.csv"

然后我用

download.file(fileURL, "Idaho2006.csv", method = "Internal") 

問題是除非您在Windows上並設置一個選項,否則download.file不能與method=internal https一起使用。 由於fread在將URL而不是本地文件傳遞給download.file時會失敗。 您必須手動下載文件,然后從本地文件打開它。

如果您使用的是Linux或已經具有以下任一功能,請改用method=wgetmethod=curl

如果您使用的是Windows,並且既不想下載又不想下載它們,請在download.file之前執行setInternet2(use = TRUE)

http://www.inside-r.org/r-doc/utils/setInternet2

例如:

fileURL <- "https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06pid.csv"
tempf <- tempfile()
download.file(fileURL, tempf, method = "curl")
DT <- fread(tempf)
unlink(tempf)

要么

fileURL <- "https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06pid.csv"
tempf <- tempfile()
setInternet2 = TRUE
download.file(fileURL, tempf)
DT <- fread(tempf)
unlink(tempf)

fread()現在利用curl軟件包下載文件。 這似乎可以正常工作的atm:

require(data.table) # v1.9.6+
fread(fileURL, showProgress = FALSE)

根據我的經驗,解決此問題的最簡單方法是從https中刪除。 同時刪除不需要的方法。 我的操作系統是Windows,我已經嘗試了以下代碼並可以工作。

fileURL <- "http://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06pid.csv"
download.file(fileURL, "Idaho2006.csv") 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM