R Excel工作簿的Download.File问题 [英] R Download.File Issue with Excel Workbook
问题描述
我正在尝试使用R的 download.file 函数。
I'm trying to download an Excel workbook using R's download.file function.
当我手动下载文件时(使用Internet Explorer或Chrome,右键单击并另存为),然后文件下载,然后我可以在Excel中打开它而没有任何问题。
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.
当我在R中使用download.file时,文件将下载并报告正确的文件大小。但是,当我随后尝试在Excel 2010中打开下载的xls文件时,出现以下错误消息:
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在'test中发现了不可读的内容.xls'。您要恢复此工作簿的内容吗?如果您信任此工作簿的来源,请单击是。
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.
我也尝试过使用R包直接访问文件 xlsx ,这也会失败。
I've also tried accessing the file directly using the R package xlsx, this also fails.
推荐答案
您可以尝试以二进制模式下载文件( download.file
的默认值为ASCII模式),并带有 mode
参数。像这样的东西:
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")
这篇关于R Excel工作簿的Download.File问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!