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.
The xlsx package, a java-based solution, is one of the powerful R packages to read, write and format Excel files.
Summary. Write data from R to Excel files using xlsx package: write. xlsx(my_data, file = “result. xlsx”, sheetName = “my_data”, append = FALSE).
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")
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