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.
These errors mean that your virus scanning software might have blocked you from downloading a file. Check your virus-scanning software for details about why the file was blocked. On Windows: Windows Attachment Manager could have removed the file you tried to download.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With