Henrik Bengtsson
2012-Aug-29 19:27 UTC
[Rd] Suggestion: Change default to download.file(..., mode="wb") ...instead of mode="w" with some bells and whistles
Hi, I keep seeing the problem where people are download binary files as text (mode="w") when using R's download.file() for FTP/HTTP downloads. It often results in unnecessary troubleshooting until one concludes that the downloaded file has been corrupted due to (what I think is) translated newlines. Search the r-help mailing list and you'll find other examples of this. This may or may not only be a problem for Windows users. I'd like to suggest to change the default of argument 'mode' of download.file() to be mode="wb". The "default" is current mode="w" except when argument 'mode' is missing (not explicitly given), download.file() tries to be helpful by forcing 'mode' to be "wb" for certain filename extensions. NB: help("download.file", package="utils") has a paragraph on all this. BTW, the latter seems to be done in a case-sensitive way, such that *.zip and *.ZIP will have different behaviors. Wouldn't it just be safer to change the default to mode="wb"? ...or are there use cases that I'm overseeing - is anyone out there intentionally using the "text" transfer mode? /Henrik
steven mosher
2012-Sep-05 16:39 UTC
[Rd] Suggestion: Change default to download.file(..., mode="wb") ...instead of mode="w" with some bells and whistles
I would second this suggestion. On Wed, Aug 29, 2012 at 12:27 PM, Henrik Bengtsson <hb@biostat.ucsf.edu>wrote:> Hi, > > I keep seeing the problem where people are download binary files as > text (mode="w") when using R's download.file() for FTP/HTTP downloads. > It often results in unnecessary troubleshooting until one concludes > that the downloaded file has been corrupted due to (what I think is) > translated newlines. Search the r-help mailing list and you'll find > other examples of this. This may or may not only be a problem for > Windows users. > > I'd like to suggest to change the default of argument 'mode' of > download.file() to be mode="wb". The "default" is current mode="w" > except when argument 'mode' is missing (not explicitly given), > download.file() tries to be helpful by forcing 'mode' to be "wb" for > certain filename extensions. NB: help("download.file", > package="utils") has a paragraph on all this. BTW, the latter seems > to be done in a case-sensitive way, such that *.zip and *.ZIP will > have different behaviors. > > Wouldn't it just be safer to change the default to mode="wb"? ...or > are there use cases that I'm overseeing - is anyone out there > intentionally using the "text" transfer mode? > > /Henrik > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >[[alternative HTML version deleted]]