Search code examples
rkaggle

Read dataset from Kaggle


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.


Solution

  • 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)