Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in file.download when downloading custom file

Tags:

r

download

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.

like image 675
user1445246 Avatar asked Nov 30 '12 19:11

user1445246


People also ask

Why do my downloads keep failing?

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.


2 Answers

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.

like image 119
user1445246 Avatar answered Oct 13 '22 11:10

user1445246


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.

like image 20
Maciej Avatar answered Oct 13 '22 10:10

Maciej