You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to publish a blog post that analyzes a dataset from Kaggle. I wish to make the blog post as reproducible as possible, thereby exposing the process of loading the data directly from the Internet. Therefore, any person trying to reproduce my steps could do it with just running my code and it'll work for them. However, downloading Kaggle datasets requires authentication, which is somewhat a spoke in the wheel of my ideal "copy & run" level of reproducibility.
The problem: translating {httr} code to {httr2}
I'm trying to download a csv file directly from the Kaggle website. I've come across this piece of code on Kaggle's website, which provides a way to download data from Kaggle via R.
However, this piece relies on {httr} rather than {httr2}, and I wonder what would be the {httr2} equivalent.
In the most common scenario, I open up RStudio when I already know:
The url to the data (e.g., https://www.kaggle.com/api/v1/datasets/download/michaelbryantds/witch-trials/trials.csv)
My credentials to access Kaggle (username & password)
When those are given, I'd like to know what the most modern way is, using {httr2} tools, to read the data as data.frame/tibble directly from the url while authenticating. Although I went over the documentation, I must admit I got lost in all the req_* functions.
The text was updated successfully, but these errors were encountered:
Once you have the request object, you can read it easily with read_csv as before by first extracting the response body as a string (since it's text) and passing that to read_csv.
Context
I want to publish a blog post that analyzes a dataset from Kaggle. I wish to make the blog post as reproducible as possible, thereby exposing the process of loading the data directly from the Internet. Therefore, any person trying to reproduce my steps could do it with just running my code and it'll work for them. However, downloading Kaggle datasets requires authentication, which is somewhat a spoke in the wheel of my ideal "copy & run" level of reproducibility.
The problem: translating
{httr}
code to{httr2}
I'm trying to download a csv file directly from the Kaggle website. I've come across this piece of code on Kaggle's website, which provides a way to download data from Kaggle via R.
However, this piece relies on
{httr}
rather than{httr2}
, and I wonder what would be the{httr2}
equivalent.Somewhat reproducible example
I randomly picked this dataset from Kaggle: Witch Trials Dataset
I got my Kaggle token from the website's menu: Account -> API -> Create New API Token
.json
file to my computer with credentials for authentication.R code with
{httr}
to get a response object:From here, I have two options to get the csv as a data.frame/tibble
httr::content()
readr::read_csv()
Bottom line question
In the most common scenario, I open up RStudio when I already know:
https://www.kaggle.com/api/v1/datasets/download/michaelbryantds/witch-trials/trials.csv
)When those are given, I'd like to know what the most modern way is, using
{httr2}
tools, to read the data as data.frame/tibble directly from the url while authenticating. Although I went over the documentation, I must admit I got lost in all thereq_*
functions.The text was updated successfully, but these errors were encountered: