37

Searching on stackoverflow questions, I found out this link: Error in file.download when downloading custom file .

However, my case is a little bit different (I think):

1) I get this annoying warning when installing some packages from CRAN (or also just some dependencies that get generally installed together with the required package).

2) The downloaded length always appear to be equal to the reported length, so there should be no warning.
As an example, I copy-paste here the warning that has just appeared in updating mgcv.

Warning message:
In download.file(url, destfile, method, mode = "wb", ...) :
  downloaded length 1886962 != reported length 1886962

The mode argument is already set to "wb", so the solution offered in the SO link does not seem to work.

It is very strange, because I have re-installed both R and RStudio recently for other reasons, but this warning has not desappeared.

Any advise is welcome.

Community
  • 1
  • 1
Davide Passaretti
  • 2,741
  • 1
  • 21
  • 32
  • Can you provide the `Sys.info()`? – Steven Beaupré Dec 20 '14 at 20:08
  • 1
    `structure(c("Windows", "7 x64", "build 9200", "VAIO", "x86-64", "one-o_000", "one-o_000", "one-o_000"), .Names = c("sysname", "release", "version", "nodename", "machine", "login", "user", "effective_user"))`. Is it normal that I have Windows 8.1 and here the release is 7? – Davide Passaretti Dec 20 '14 at 20:40
  • 2
    I had this problem for the first time the other day. Like yours, I got the warnings, in the warning the printed lengths *did* match. The installation seemed to work anyway... – Gregor Thomas Dec 20 '14 at 22:21
  • 1
    Same here, and I'm working on win 8 too. here my Sys.info: ` Sys.info() sysname release version nodename machine login user effective_user "Windows" "7 x64" "build 9200" "K*****" "x86-64" "g*****" "g******" "g******"` It too says it's running on 7. – PavoDive Dec 21 '14 at 02:23
  • Got the same. I suspect antivirus or other protection software. I have McAfee and Symantec Endpoint Protection. Is this crossing with you @PavoDive, @DavidePassaretti? – Marek Jan 20 '15 at 09:47
  • I have avast but still have also some extensions belonging to McAfee which was by default installed in my windows 8 copy (I just removed the core). – Davide Passaretti Jan 20 '15 at 18:28
  • 2
    This sounds like a bug, and [should probably be reported](https://bugs.r-project.org/bugzilla3/). – Konrad Rudolph Jan 20 '15 at 18:48
  • 2
    @KonradRudolph It's actually an RStudio bug, as I only encounter that problem when working in RStudio. – Joris Meys Mar 18 '15 at 13:51
  • I am having the same issue while trying to install the package 'BH' on my VDI. It seems that the package zip is so large and the network drive is so slow that somehow the the number of bytes are not equal. Any work-around to bypass this error and trust the package? – Scott Dec 02 '16 at 11:47
  • You can use R instead of RStudio to install your packages. But now I have no idea about the reason. – maggie Jul 31 '17 at 07:17
  • Can help me with this related post please? https://stackoverflow.com/questions/61200536/r-unable-to-install-r-packages-cannot-open-the-connection – The Great Apr 14 '20 at 08:11

5 Answers5

6

increase the max timeout option beyond the default setting

Try: options(timeout = max(1000, getOption("timeout")))

This issue is typically caused by trying to download a large file (> 50 MB) that it exceeds the "timeout" option built-into R. The cryptic error message indicates that the amount downloaded is less than the total requested amount, because the request was killed mid-way. From the ?download.file() docs:

The timeout for many parts of the transfer can be set by the option timeout which defaults to 60 seconds. This is often insufficient for downloads of large files (50MB or more) and so should be increased when download.file is used in packages to do so. Note that the user can set the default timeout by the environment variable R_DEFAULT_INTERNET_TIMEOUT in recent versions of R, so to ensure that this is not decreased packages should use something like

options(timeout = max(300, getOption("timeout")))
Rich Pauloo
  • 7,734
  • 4
  • 37
  • 69
  • thanks this solved a similar problem for me, though for me the reported and downloaded sizes were not identical. – PaulB Nov 11 '21 at 20:29
1

I had encountered the same problems on windows or linux server. I believed that this is probably caused by the network speed. I tried to install this package for the second or even the third time (using the function install.packages) or manually download the desired package from CRAN and then installed it and that fixed the problem.

Ven Yao
  • 3,680
  • 2
  • 27
  • 42
1

I solved my problem by going to this site and downloading the required package. The problem of different lengths was due to the inability to download the folder completely from R so I did download it directly and call it from the install button in Packages and selecting zip file rather than CRAN. Then just select the folder and that was for me the solution.

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
0

For reference:

I am running Windows Vista, and am getting the same error for various package installs (where the download size is reported to not equal the reported length despite the numbers displayed being equal). The packages appear to install correctly, despite the reported error.

RStudio version 0.98.1091

> SysInfo()

release                                                 Vista x64
version                                build 6002, Service Pack 2

> version

platform       x86_64-w64-mingw32          
version.string R version 3.1.2 (2014-10-31)

My guess (without any knowledge of the internals of the install.packages code) is that while integers are being reported, they are not being compared as integers, and so throwing the error.

MichaelNJ
  • 46
  • 1
  • 6
0

After reading that this was happening because of a time out during downloading, I switched to a faster internet connection and everything immediately worked as expected.

stevec
  • 41,291
  • 27
  • 223
  • 311