从Kaggle读取数据集

时间:2019-03-21 02:26:11

标签: r kaggle

我正在尝试使用以下命令将数据从Kaggle下载到R中。我尝试下载的数据集位于here

library(httr)
dataset <- GET("https://www.kaggle.com/api/v1/competitions/data/download/10445/train.csv", 
         authenticate(username, authkey, type = "basic"))

变量dataset的类型为"application/zip"。有人可以帮我从链接内部获取csv文件吗?(我使用http_type(train),如果我的问题不清楚,请告诉我

编辑:包括基于注释的库名。

1 个答案:

答案 0 :(得分:0)

我根据发布的here的答案找到了解决方案。有人在评论中发布了链接,但我不再看到评论。谢谢撒玛利亚人!

library(httr)
dataset <- httr::GET("https://www.kaggle.com/api/v1/competitions/data/download/10445/train.csv", 
                 httr::authenticate(username, authkey, type = "basic"))

temp <- tempfile()
download.file(dataset$url,temp)
data <- read.csv(unz(temp, "train.csv"))
unlink(temp)