1717download_zip_data <- function (force = FALSE ) {
1818
1919 # Define URLs for downloading external datasets used in the package
20- url_crosswalk <- " https://github.com/gavinrozzi/zipcodeR-data/blob/master/zip_to_cd .rda?raw=true"
20+ url_crosswalk <- " https://github.com/gavinrozzi/zipcodeR-data/blob/master/zcta_crosswalk .rda?raw=true"
2121 url_cd <- " https://github.com/gavinrozzi/zipcodeR-data/blob/master/zip_to_cd.rda?raw=true"
2222
23- # Test if data dir exists and create
24- if (dir.exists(paste0(system.file(package = " zipcodeR" ), " /data" )) == TRUE ) {
25- cat(" Data directory exists - moving to download phase" )
26- } else if (dir.exists(paste0(system.file(package = " zipcodeR" ), " /data" )) == FALSE ) {
27- cat(" Creating data directory" )
28- dir.create(paste0(system.file(package = " zipcodeR" ), " /data" ))
29- }
30-
3123 # Test if ZCTA crosswalk file exists, download if not present
3224 if (file.exists(system.file(" data" , " zcta_crosswalk.rda" , package = " zipcodeR" )) == TRUE && force == FALSE ) {
3325 cat(" Crosswalk file found, skipping" )
3426 } else if (file.exists(system.file(" data" , " zcta_crosswalk.rda" , package = " zipcodeR" )) == FALSE ) {
35- cat(" Downloading ZCTA crosswalk file" )
27+ cat(paste( " zipcodeR: Downloading ZCTA crosswalk file" , " \n " ) )
3628 utils :: download.file(url_crosswalk , paste0(system.file(" data" , package = " zipcodeR" ), " /zcta_crosswalk.rda" ))
3729 } else if (force == TRUE ) {
38- cat(" Forcing Download of ZCTA crosswalk file" )
30+ cat(paste( " zipcodeR: forcing Download of ZCTA crosswalk file" , " \n " ) )
3931 utils :: download.file(url_crosswalk , paste0(system.file(" data" , package = " zipcodeR" ), " /zcta_crosswalk.rda" ))
4032 }
4133
@@ -61,9 +53,6 @@ download_zip_data <- function(force = FALSE) {
6153 # Store the latest download URL from GitHub
6254 file_name <- zip_db_url $ browser_download_url
6355
64- # Store the latest version of zip_code_db to internal package data
65- version <- as.Date(zip_db_url $ created_at )
66- save(version , file = paste0(system.file(" R" , package = " zipcodeR" ), " /sysdata.rda" ))
6756
6857 # create a temporary directory and file for downloading the data
6958 td <- tempdir()
@@ -90,17 +79,21 @@ download_zip_data <- function(force = FALSE) {
9079 # Read in the new data
9180 zip_code_db <- dbGetQuery(conn , " SELECT * FROM simple_zipcode" )
9281
93- # Save the updated RData file to package data directory
82+ # Save the updated zip_code_db file to package data directory
9483 save(zip_code_db , file = paste0(system.file(" data" , package = " zipcodeR" ), " /zip_code_db.rda" ))
9584
85+ # Save the latest version of zip_code_db to internal package data
86+ zip_code_db_version <- as.Date(zip_db_url $ created_at )
87+ save(zip_code_db_version , file = paste0(system.file(" R" , package = " zipcodeR" ), " /sysdata.rda" ))
88+
9689 # Tear down the database connection
9790 RSQLite :: dbDisconnect(conn )
9891
9992 # Test if congressional district relationship file exists, download if not present
10093 if (file.exists(system.file(" data" , " zip_to_cd.rda" , package = " zipcodeR" )) == TRUE && force == FALSE ) {
10194 cat(" Congressional district file found, skipping" )
10295 } else if (file.exists(system.file(" data" , " zip_to_cd.rda" , package = " zipcodeR" )) == FALSE ) {
103- cat(" Downloading congressional district data file" )
96+ cat(" zipcodeR: Downloading congressional district data file" )
10497 utils :: download.file(url_cd , paste0(system.file(" data" , package = " zipcodeR" ), " /zip_to_cd.rda" ))
10598 } else if (force == TRUE ) {
10699 cat(" Forcing download of congressional district data file" )
0 commit comments