Read dataset from Kaggle

不羁的心 提交于 2020-08-09 08:13:33

问题


I am trying to download data into R from Kaggle using the below command. The datasets I am trying to download are located here.

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

The variable dataset is of type "application/zip". Can someone help me get the csv file from inside the link?(I used http_type(train) Please let me know if my question is unclear

Edit: Included library name based on comments.


回答1:


I found a solution based on the answer posted here. Someone posted the link in the comment but I don't see the comment any more. Thank you Good Samaritan!

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)


来源:https://stackoverflow.com/questions/55272909/read-dataset-from-kaggle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!