Reputation: 1917
I'm trying to download an Excel workbook using R's download.file function.
When I download the file manually (using Internet Explorer or Chrome, right click & save as) then the file downloads and I can then open it in Excel without any problems.
When I use download.file in R, the file downloads and reports the correct file size. However when I then try to open the downloaded xls file in Excel 2010 I get the following error message:
Excel found unreadable content in 'test.xls'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes.
When I click Yes, nothing happens.
I've also tried accessing the file directly using the R package xlsx, this also fails.
Upvotes: 27
Views: 8436
Reputation: 49033
You can try to download your file in binary mode (default for download.file
is ASCII mode) with the mode
argument. Something like :
download.file(myurl, mydestfile, mode="wb")
Upvotes: 54