Reputation: 83
I have a zip file containing data in a private Github repo. I am writing some R code, and I wish to download the data into R. When I run the following code I get a HTTP status was '404 Not Found'. This doesn't happen when the repo is bublic, though.
How can I fix the code to be able to download the file? I believe I need to get a access token, but I don't know well how to get that either and add it to the code. If someone could help, I would appreciate a lot. Thanks.
# We give the url a name
url <- "https://github.com/aquijanoruiz/disability_benefits_EC/raw/master/ENSANUT_datasets/BDD_ENSANUT_2018_STATA_.zip"
# We create a temporary directory
td <- tempdir()
# We create the placeholder file
tf <- tempfile(tmpdir=td, fileext = ".zip")
# We download the data into the placeholder file
download.file(url,tf)
Upvotes: 5
Views: 1857
Reputation: 1323115
From r 3.6.2 download.file
, you would need at least to add a header, with Authorization: token xxx
in it, in order to be properly authenticated (thus having the right to read the repository content).
Use a PAT (Personnal Access Token)
Adding a media type is also recommended, as seen in "How can I download a single raw file from a private GitHub repo using the command line?", but probably not needed in your case, since you are using the /raw/
URL directly.
I would use remote.download
, which wraps download.file, and allows to easily set an auth_header
download(".", url, "<yourToken>")
The OP Alonso Quijano, however, had to resort to a workaround (from the comments):
I Uploaded the file to my google drive, where a token is not needed, just the url.
As noted by Kai Aragaki in the comments:
The
download()
function from remotes isn't exported, so you must access it withremotes:::download()
(note the three colons instead of two)
Upvotes: 4