Skip to content

Instantly share code, notes, and snippets.

@jrosell
Created May 9, 2022 15:28
Show Gist options
  • Save jrosell/9ca888e13f55d1101101adb7fbe8dd3a to your computer and use it in GitHub Desktop.
Save jrosell/9ca888e13f55d1101101adb7fbe8dd3a to your computer and use it in GitHub Desktop.
kgl_competitions_data_download <- function(competition_id, file_name, path = ".") {
.kaggle_base_url <- "https://www.kaggle.com/api/v1"
url <- paste0(.kaggle_base_url, "/competitions/data/download/", competition_id, "/", file_name)
rcall <- httr::GET(url, httr::authenticate(Sys.getenv("KAGGLE_USER"), Sys.getenv("KAGGLE_KEY"), type = "basic"))
tmp <- tempfile()
download.file(rcall$url, tmp)
invisible(file.copy(tmp, paste0(path, "/", file_name)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment