Reputation: 303
I'm trying to download the zip file from this url:
url1 <- http://www.clinicaltrials.gov/ct2/results?cond=%22acne%22&studyxml=true
Here's my code:
tempZip <- tempfile()
download.file(url1, tempZip)
And here's the error I get:
Warning message:
In download.file(url1, tempZip) :
downloaded length 817445 != reported length 200
Any ideas?
EDIT: OK, after seeing agstudy's reply below, I found that the file was indeed being downloaded (it also appears to be the correct file size). Now the problem is when I try to unzip the file - it days the file is corrupted.
Maciej, I agree that it would be better to use a link with a .zip extension, however, there's no way to get that from this website.
Upvotes: 8
Views: 4062
Reputation: 303
OK, I figured out what was wrong. Because this url does not specifically have ".zip" at the end, the download.file function does not know to use a binary download. This code fixes the problem:
url1 <- http://www.clinicaltrials.gov/ct2/results?cond=%22acne%22&studyxml=true
tempZip <- tempfile()
download.file(url1, tempZip, mode="wb")
If you don't specify the mode argument, the downloaded zip file will be corrupt.
Upvotes: 8
Reputation: 3303
You don't have direct link to the file. R try to download webpage not file. Use link which end with '.zip'.
Maybe useful be using XML
or RCurl
package to scrape links to datasets from this webpage.
Upvotes: 2