我有a CSV file (24.1 MB),我無法完全讀入我的R會話。當我在電子表格程序中打開文件時,可以看到112,544行。當我與read.csv
讀入R I只得到56952行,這樣的警告:read.csv警告'引用字符串中的EOF'阻止完整讀取文件
cit <- read.csv("citations.CSV", row.names = NULL,
comment.char = "", header = TRUE,
stringsAsFactors = FALSE,
colClasses= "character", encoding= "utf-8")
Warning message:
In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
EOF within quoted string
我可以readLines
讀取整個文件到R:
rl <- readLines(file("citations.CSV", encoding = "utf-8"))
length(rl)
[1] 112545
但我不能把它恢復爲R爲表(通過read.csv
):
write.table(rl, "rl.txt", quote = FALSE, row.names = FALSE)
rl_in <- read.csv("rl.txt", skip = 1, row.names = NULL)
Warning message:
In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
EOF within quoted string
我該如何解決或變通方法此EOF消息(這似乎是超過一個警告錯誤的),以獲得整個文件導入我的R
會話?
我也有類似的問題,閱讀的CSV文件等方法:()
require(sqldf)
cit_sql <- read.csv.sql("citations.CSV", sql = "select * from file")
require(data.table)
cit_dt <- fread("citations.CSV")
require(ff)
cit_ff <- read.csv.ffdf(file="citations.CSV")
這裏是我的sessionInfo
R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] tools tcltk stats graphics grDevices utils datasets methods base
other attached packages:
[1] ff_2.2-11 bit_1.1-10 data.table_1.8.8 sqldf_0.4-6.4
[5] RSQLite.extfuns_0.0.1 RSQLite_0.11.4 chron_2.3-43 gsubfn_0.6-5
[9] proto_0.3-10 DBI_0.2-7
謝謝,這是一個簡單的修復。現在你怎麼看待fread在這種情況下工作?我更喜歡這樣做,因爲它比'read.csv'快得多。但'fread'似乎並沒有引用'quote'的參數。 – Ben
@Ben我試圖讓它工作也沒有成功,正如你指出的那樣'fread'對嵌入式引號不會很好,但我肯定會很快有一個解決方法。 http://stackoverflow.com/questions/16094025/data-tablefread-and-unbalanced – dickoa
我看,謝謝檢查。 – Ben