# 2.3 MB file
download.file("http://www.nzta.govt.nz/resources/crash-analysis-system-data/docs/crash-data-2014.csv"
, "temp.csv")
# Blank lines cause fread to fail
data.table::fread("temp.csv")
# Empty data.table (0 rows) of 29 cols: TLA NAME,CRASH ROAD,CRASH DIST,CRASH DIRN,INTSN,SIDE ROAD...
在Notepad ++中打开文件表明在每个CRLF字符对后插入了一个额外的CR字符。如果我通过浏览器(Chrome)下载文件,则不会发生这种情况。
发生了什么事?
不幸的是,我在Windows XP上。
sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: i386-w64-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_New Zealand.1252 LC_CTYPE=English_New Zealand.1252 LC_MONETARY=English_New Zealand.1252
[4] LC_NUMERIC=C LC_TIME=English_New Zealand.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] data.table_1.9.2 plyr_1.8.1 Rcpp_0.11.3 reshape2_1.4 stringr_0.6.2 tools_3.1.1
答案 0 :(得分:3)
download.file(url, destfile, mode = "wb")