Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(httr)
- library(utils)
- url_path <- 'https://data.police.uk/data/archive/2022-12.zip'
- # Make a GET request to the URL and stream the response
- response <- httr::GET(url_path, stream = TRUE)
- # Open a connection to the streamed response
- con <- rawConnection(response$content, "rb")
- # Open the connection as a .zip file
- zip_file <- unzip(con, exdir = ".", list = TRUE)
- # Iterate over the files in the .zip file
- for (file_name in zip_file$Name) {
- if (grepl("\\.street\\.", file_name)) {
- print(file_name)
- # Extract the file into the current working directory
- unzip(con, files = file_name, exdir = ".", junkpaths = TRUE)
- print(paste0("Finished saving ", file_name))
- }
- }
- # Close the connection
- close(con)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement