1

The question is simple and there are similar questions in other languages, but not in R, as far as I could search.

I want to download a file in R code, but before downloading, I want to print out the size and estimation of the download time. Is there any way to do this directly in base R, or using curl utilities?

MEcon
  • 395
  • 4
  • 23
  • Does this answer your question? [How to check file size before opening in R](https://stackoverflow.com/questions/30580798/how-to-check-file-size-before-opening-in-r) – LocoGris Sep 11 '20 at 18:09
  • The accepted answer does not. But there is another answer that helps. But the answer provided here is better at answering the question. – MEcon Sep 12 '20 at 06:15

1 Answers1

5

A simple solution would be:

download_size <- function(url) as.numeric(httr::HEAD(url)$headers$`content-length`)

Which would allow

download_size("https://cran.r-project.org/doc/manuals/r-release/R-ints.pdf")
#> [1] 452557
Allan Cameron
  • 147,086
  • 7
  • 49
  • 87