Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R + download.file warning doesn't make sense to me

Tags:

r

I don't understand the warning message:

Warning message: In download.file(url, temp, quiet = TRUE, mode = "wb") : downloaded length 2533 != reported length 2533

If the numbers were different, I could understand. The code to reproduce:

url <- "http://www.waterqualitydata.us/Result/search?siteid=USGS-01594440&pCode=01075&countrycode=US&mimeType=tsv&zip=yes"
temp <- tempfile()
download.file(url,temp, quiet=TRUE, mode='wb')
doc <- unzip(temp)
unlink(temp)
retval <- read.delim(doc , header = TRUE, quote="\"", 
                  dec=".", sep='\t', 
                  fill = TRUE)

I can suppress the warning, but I want to make sure I'm not doing anything wrong either. Thanks!

edit: added the read.delim part to get a dataframe out. My platform is x86_64-w64-mingw32/x64 (64-bit), with R version 3.1.2 (2014-10-31).

like image 448
user3915170 Avatar asked Dec 15 '14 20:12

user3915170


1 Answers

I am also on Platform: x86_64-w64-mingw32/x64 (64-bit) and do not have this problem under R 3.1.3. I get retval returned with 65 obs of 62 variables.

user3915170, just to reiterate what others have said above.

  1. First try upgrade R version from Pumpkin Helmet as @Stedy suggests.

    And let us know if it is still a problem.

  2. Check your quote marks on sep. I noticed you have them as single not double. (It worked for me as you had them, but might be an issue on R3.1.2)

    retval <- read.delim(doc, header = TRUE, quote="\"", 
                     dec = ".", sep = "\t", 
                     fill = TRUE)
    

    read.delim is just a special case of read.table with set defaults - from help "default(s) to the TAB character for the delimiter." So this sep setting is unnecessary and may be the fly in the ointment. So try it also without the sep operator, and see if you get the warning.

  3. Something similar has cropped up before on Stack Overflow but with a wider mismatch - only getting 200 bytes back.

    You are using mode='wb' which fixed https://stackoverflow.com/a/13803331/4606130. Not understanding type is something Konrad suggested whose comment is lost lower down in the comment list.

    But issue 16761056 had others there suggesting checking network connections, or a problem in download.file function. Have you tried running code from another location? All long shots but at least you are not alone with these warning messages!

Good luck and hope the upgrade solves this!

M

like image 81
micstr Avatar answered Oct 25 '22 08:10

micstr