在R中下载并读取Zip CSV文件

时间:2015-11-04 16:15:26

标签: r csv zip kaggle

我正在尝试从R脚本中的Kaggle下载并读取压缩的csv文件。在研究了包括post1post2在内的其他帖子后,我尝试过:

# Read data with temp file
url <- "https://www.kaggle.com/c/rossmann-store-sales/download/store.csv.zip"
tmp <- tempfile()
download.file(url, tmp, mode = "wb")
con <- unz(tmp, "store.csv.zip")
store <- read.table(con, sep = ",", header = TRUE)
unlink(tmp)

read.table命令抛出错误:

Error in open.connection(file, "rt") : cannot open the connection

我也尝试过:

# Download file, unzip, and read
url <- "https://www.kaggle.com/c/rossmann-store-sales/download/store.csv.zip"
download.file(url, destfile = "./SourceData/store.csv.zip", mode = "wb")
unzip("./SourceData/store.csv.zip")

解压缩会抛出错误:

error 1 in extracting from zip file

绕过解压缩命令并直接从zip文件中读取

store <- read_csv("SourceData/store.csv.zip")

引发错误:

zip file ... SourceData/store.csv.zip cannot be opened

我更喜欢使用临时文件,但此时我会使用这两种方法,如果我可以使用它。

0 个答案:

没有答案