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.
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")))
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With