[英]How to determine the file size of a remote download without reading the entire file with R
[英]How to determine online file size before download in R?
問題很簡單,其他語言中也有類似的問題,但在 R 中沒有,據我所知。
我想用R代碼下載一個文件,但是在下載之前,我想打印出下載時間的大小和估計。 有沒有辦法直接在基本 R 中執行此操作,或使用 curl 實用程序?
一個簡單的解決方案是:
download_size <- function(url) as.numeric(httr::HEAD(url)$headers$`content-length`)
這將允許
download_size("https://cran.r-project.org/doc/manuals/r-release/R-ints.pdf")
#> [1] 452557
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.