Ho un file CSV (24,1 MB) che non riesco a leggere completamente nella mia sessione R. Quando apro il file in un programma per fogli di calcolo, vedo 112.544 righe. Quando lo leggo in R con read.csvottengo solo 56.952 righe e questo avviso:
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
Posso leggere l'intero file in R con readLines:
rl <- readLines(file("citations.CSV", encoding = "utf-8"))
length(rl)
[1] 112545
Ma non riesco a riportarlo in R come tabella (tramite 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
Come posso risolvere o aggirare questo messaggio EOF (che sembra essere più un errore che un avvertimento) per ottenere l'intero file nella mia Rsessione?
Ho problemi simili con altri metodi di lettura dei file 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")
Ecco la mia sessioneInfo ()
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
freadlavorare in questa situazione? Lo preferisco perché è molto più veloce diread.csv. Mafreadnon sembraquotediscutere.