[R] download.file not working

Henrik Bengtsson hb at stat.berkeley.edu
Thu Oct 11 19:05:16 CEST 2007


On 10/11/07, Gustaf Rydevik <gustaf.rydevik at gmail.com> wrote:
> > So, if you download the same file using a web browser it works, ehe?
> > Then look at the file size and you'll most likely find that it is
> > different from when you use R code.  Conclusion?  Something is
> > different and it works in the web browser so you might tell R to do
> > something different from what you would expect.  Hint, look at the set
> > of arguments download.file() takes.
> >
> > That's my $0.02
> >
> > Henrik
> >
> >
>
> After using the argument mode="wb", the downloaded file is OK.
> Thank you very much for your comments, Henrik.
>
>  I've got no  real idea of what the "mode="wb"" argument means, so if
> someone could give an explanation, or a reference, I'd be most
> grateful.

When you transfer something in "binary" mode, you will receive an
identical copy of the file, that is, every the number of bytes and
each byte of the file is the same as the source file.  When you
transfer in "text/ASCII" mode, it is assumed that the file is a text
file, and the exact byte contents of text files vary between
platforms, especially end-of-line characters which can be either "\n",
"\r", "\r\n" (I might got the ordering wrong).  In "text" mode, the
byte contents is modified to meet the receivers platforms, so
typically some bytes are added or removed at the end of each text
line.

I your case the Excel file is certainly not a text file, but it was
interpreted as such by download.file() and some of its bytes where
interpreted as end-of-line characters and translated.

The above does not only apply to R but many other transfer protocols, e.g. FTP.

/H

>
> Best
>
> Gustaf
> --
> Gustaf Rydevik, M.Sci.
> tel: +46(0)703 051 451
> address:Essingetorget 40,112 66 Stockholm, SE
> skype:gustaf_rydevik
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list