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")
libcurl (the default) fails.
Looking at the source code of
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)
# another package (works)
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.