rcurlhttr2

how to download a zipped file from https://www2.census.gov within R


I'm curious if there's a straightforward way to download this data file within an R session? This zipped file downloads without any issues in both firefox and chrome for me:

https://www2.census.gov/programs-surveys/cps/datasets/2024/march/asecpub24sas.zip

I'm not sure if the security settings on https://www2.census.gov/ might have changed because although this download command has not worked for a long time..

tf <- tempfile()

this_url <- "https://www2.census.gov/programs-surveys/cps/datasets/2024/march/asecpub24sas.zip"

download.file( this_url , tf , mode = 'wb' )

..I think that this httr command worked until recently?

library(httr)

GET( this_url , write_disk( tf ) , progress() )

The same command does work when used on https://web.archive.org

archive_url <-  
    "https://web.archive.org/web/https://www2.census.gov/programs-surveys/cps/datasets/2024/march/asecpub24sas.zip"

GET( archive_url , write_disk( tf , overwrite = TRUE ) , progress() )

Solution

  • You can use curl::curl_download for ftp requests, if download speed is not a big concern. This one worked for me, although it was really slow.

    ftp <- "ftp://ftp2.census.gov/programs-surveys/cps/datasets/2024/march/asecpub24sas.zip"
    curl::curl_download(ftp, basename(ftp), quiet = FALSE)