Hi all, I'm trying to download a file from the net, and the download.file command leaves it corrupted, i.e excel cannot open it. It seems as if it's going ok, however. Does anyone have an idea of what's going on? regards, Gustaf Rydevik ---->download.file(url="http://www.who.int/entity/whosis/whostat2006_demographics.xls",destfile="whodem.xls")trying URL 'http://www.who.int/entity/whosis/whostat2006_demographics.xls' Content type 'application/vnd.ms-excel' length 77824 bytes opened URL downloaded 76Kb> sessionInfo()R version 2.5.0 (2007-04-23) i386-pc-mingw32 locale: LC_COLLATE=Swedish_Sweden.1252;LC_CTYPE=Swedish_Sweden.1252;LC_MONETARY=Swedish_Sweden.1252;LC_NUMERIC=C;LC_TIME=Swedish_Sweden.1252 attached base packages: [1] "stats" "graphics" "grDevices" "utils" "datasets" "methods" [7] "base" other attached packages: RWinEdt "1.7-5"> Sys.getlocale()[1] "LC_COLLATE=Swedish_Sweden.1252;LC_CTYPE=Swedish_Sweden.1252;LC_MONETARY=Swedish_Sweden.1252;LC_NUMERIC=C;LC_TIME=Swedish_Sweden.1252">-- Gustaf Rydevik, M.Sci. tel: +46(0)703 051 451 address:Essingetorget 40,112 66 Stockholm, SE skype:gustaf_rydevik
Prof Brian Ripley
2007-Oct-10 15:42 UTC
[R] download.file used incorrectly (was not working)
On Wed, 10 Oct 2007, Gustaf Rydevik wrote:> Hi all, > > I'm trying to download a file from the net, and the download.file > command leaves it corrupted, i.e excel cannot open it. It seems as if > it's going ok, however. > Does anyone have an idea of what's going on?That is a binary file. You needed mode="wb". The R posting guide did ask you to update your R before posting, so better late than never.> > regards, > > Gustaf Rydevik > > ---- >> download.file(url="http://www.who.int/entity/whosis/whostat2006_demographics.xls",destfile="whodem.xls") > trying URL 'http://www.who.int/entity/whosis/whostat2006_demographics.xls' > Content type 'application/vnd.ms-excel' length 77824 bytes > opened URL > downloaded 76Kb >> sessionInfo() > R version 2.5.0 (2007-04-23) > i386-pc-mingw32 > > locale: > LC_COLLATE=Swedish_Sweden.1252;LC_CTYPE=Swedish_Sweden.1252;LC_MONETARY=Swedish_Sweden.1252;LC_NUMERIC=C;LC_TIME=Swedish_Sweden.1252 > > attached base packages: > [1] "stats" "graphics" "grDevices" "utils" "datasets" "methods" > [7] "base" > > other attached packages: > RWinEdt > "1.7-5" >> Sys.getlocale() > [1] "LC_COLLATE=Swedish_Sweden.1252;LC_CTYPE=Swedish_Sweden.1252;LC_MONETARY=Swedish_Sweden.1252;LC_NUMERIC=C;LC_TIME=Swedish_Sweden.1252" >> > > >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
On 10/10/07, Gustaf Rydevik <gustaf.rydevik at gmail.com> wrote:> Hi all, > > I'm trying to download a file from the net, and the download.file > command leaves it corrupted, i.e excel cannot open it. It seems as if > it's going ok, however. > Does anyone have an idea of what's going on? > > regards, > > Gustaf Rydevik > > ---- > >download.file(url="http://www.who.int/entity/whosis/whostat2006_demographics.xls",destfile="whodem.xls") > trying URL 'http://www.who.int/entity/whosis/whostat2006_demographics.xls' > Content type 'application/vnd.ms-excel' length 77824 bytes > opened URL > downloaded 76KbSo, 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> > sessionInfo() > R version 2.5.0 (2007-04-23) > i386-pc-mingw32 > > locale: > LC_COLLATE=Swedish_Sweden.1252;LC_CTYPE=Swedish_Sweden.1252;LC_MONETARY=Swedish_Sweden.1252;LC_NUMERIC=C;LC_TIME=Swedish_Sweden.1252 > > attached base packages: > [1] "stats" "graphics" "grDevices" "utils" "datasets" "methods" > [7] "base" > > other attached packages: > RWinEdt > "1.7-5" > > Sys.getlocale() > [1] "LC_COLLATE=Swedish_Sweden.1252;LC_CTYPE=Swedish_Sweden.1252;LC_MONETARY=Swedish_Sweden.1252;LC_NUMERIC=C;LC_TIME=Swedish_Sweden.1252" > > > > > -- > 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. >