RStudio is Crashing?

Dear All,
I tried running this code on R4.21 and Rstudio, and it crashes.

library(magrittr)
link <- 1951:1960 %>% 
  paste0("year%5B%5D=", ., collapse = "&") %>% 
  paste0("https://api.unhcr.org/population/v1/population/?limit=20&dataset=population&displayType=totals&columns%5B%5D=refugees&columns%5B%5D=asylum_seekers&columns%5B%5D=idps&columns%5B%5D=vda&columns%5B%5D=stateless&columns%5B%5D=ooc&", ., "&coo_all=true&coa_all=true&download=true")

utils::download.file(link, "UN_HCR_Data.zip", mode = "wb")
  

Interesting. It doesn't come from RStudio, but R. I can reproduce the problem on Windows with R4.2.x; the download works properly on R4.1. This coincides with the switch of default download method from wininet to libcurl, and indeed these work:

 utils::download.file(link, "UN_HCR_Data.zip", mode = "wb", method = "wininet")
 utils::download.file(link, "UN_HCR_Data.zip", mode = "wb", method = "curl")

While using libcurl (the default) fails.

Looking at the source code of download.file(), using method = curl uses system() to call curl in the OS, whereas method = libcurl uses a C function (part of R source), called curlDownload(). We can check the version:

# method = curl (works)
> system("curl --version")
curl 7.83.1 (Windows) libcurl/7.83.1 Schannel
[...]
# method = libcurl (fails)
> libcurlVersion()
[1] "7.83.0"
[...]
# another package (works)
> curl::curl_version()
[1] "7.64.1"
[...]

So, either it is a bug in libcurl 7.83.0 that was corrected in 7.83.1, or it is a bug in R's code calling libcurl. You can check if you have the same versions.

it is a bug in R and it is solved via
https://bugs.r-project.org/show_bug.cgi?id=18374

utils::download.file(link, "UN_HCR_Data.zip", mode = "wb", quiet=TRUE)
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.