我正在尝试在 R 脚本中从 Kaggle 下载和读取压缩的 csv 文件。在研究了包括post1和post2在内的其他帖子后,我尝试过:
# 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
绕过解压缩命令,直接从压缩文件中读取
store <- read_csv("SourceData/store.csv.zip")
抛出错误:
zip file ... SourceData/store.csv.zip cannot be opened
我更喜欢使用临时文件,但在这一点上,如果我能让它工作,我将使用任何一种方法。