Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Download.File Issue with Excel Workbook

Tags:

r

excel

download

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.

like image 678
Tumbledown Avatar asked Mar 06 '13 14:03

Tumbledown


People also ask

Can R open xlsx files?

The xlsx package, a java-based solution, is one of the powerful R packages to read, write and format Excel files.

How do I convert an xlsx file to R?

Summary. Write data from R to Excel files using xlsx package: write. xlsx(my_data, file = “result. xlsx”, sheetName = “my_data”, append = FALSE).


1 Answers

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") 
like image 109
juba Avatar answered Sep 28 '22 13:09

juba