Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
^temporary-scripts$
\.Rmd\.orig$
^vignettes/precompile\.R$
^reviews$
^\.claude$
21 changes: 12 additions & 9 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ Description: This packages combines a set of utilities for acquiring and process
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.3
Imports:
Imports:
arrow,
censusapi,
crosswalk,
curl,
sfarrow,
dplyr,
esri2sf (>= 0.1.1),
ellmer,
glue,
ggplot2,
httr,
httr2,
ipumsr,
janitor,
jsonlite,
Expand All @@ -43,7 +45,6 @@ Imports:
rfema (>= 1.0.0),
rlang,
rvest,
scales,
sf,
stringr,
tibble,
Expand All @@ -52,21 +53,23 @@ Imports:
tidytable,
tigris,
utils,
uuid,
urbnindicators,
urbnthemes
uuid
Remotes:
ropensci/rfema,
yonghah/esri2sf,
UI-Research/urbnindicators,
UI-Research/crosswalk,
UrbanInstitute/urbnthemes
URL: https://ui-research.github.io/climateapi/
Suggests:
ggplot2,
knitr,
qualtRics,
rmarkdown,
scales,
testthat (>= 3.0.0),
tidyverse
tidyverse,
urbnthemes
Config/testthat/edition: 3
VignetteBuilder: knitr
Config/roxygen2/version: 8.0.0
RoxygenNote: 7.3.2
12 changes: 3 additions & 9 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
export(cache_it)
export(convert_table_text_to_dataframe)
export(download_openfema_datasets)
export(estimate_units_per_parcel)
export(estimate_zoning_envelope)
export(get_box_path)
export(get_business_patterns)
Expand All @@ -16,9 +15,11 @@ export(get_hazard_mitigation_assistance)
export(get_ihp_registrations)
export(get_lodes)
export(get_naics_codes)
export(get_national_risk_index)
export(get_nfip_claims)
export(get_nfip_policies)
export(get_nfip_residential_penetration)
export(get_openfema_cache_path)
export(get_preliminary_damage_assessments)
export(get_public_assistance)
export(get_sba_loans)
Expand All @@ -28,15 +29,8 @@ export(get_structures)
export(get_system_username)
export(get_wildfire_burn_zones)
export(inflation_adjust)
export(interpolate_demographics)
export(list_openfema_endpoints)
export(polygons_to_linestring)
export(qualtrics_define_missing)
export(qualtrics_format_metadata)
export(qualtrics_get_metadata)
export(qualtrics_plot_question)
export(read_ipums_cached)
export(read_xlsx_from_url)
export(subdivide_linestring)
importFrom(magrittr,"%>%")
importFrom(rlang,":=")
importFrom(rlang,.data)
5 changes: 5 additions & 0 deletions R/climateapi-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#' @keywords internal
"_PACKAGE"

#' @importFrom rlang .data
NULL
22 changes: 18 additions & 4 deletions R/download_openfema_datasets.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,25 @@ download_openfema_datasets <- function(
}

message("[", name, "] Downloading ", chosen_format, " from: ", chosen_url)
old_timeout <- getOption("timeout")
on.exit(options(timeout = old_timeout), add = TRUE)
options(timeout = 1200)
## download to a temporary path and rename only on success: a truncated file
## would otherwise be served by find_openfema_cache_file() and fail to parse.
## curl::multi_download() resumes interrupted transfers, which multi-GB
## datasets (e.g. FimaNfipPolicies, ~5 GB) need on connections that drop
## mid-transfer; the .partial file is kept on failure so a later attempt or
## re-run picks up where it left off rather than restarting from zero
temp_path <- paste0(file_path, ".partial")
dl_result <- tryCatch({
utils::download.file(chosen_url, destfile = file_path, mode = "wb", quiet = FALSE)
attempts <- 0
repeat {
attempts <- attempts + 1
download_result <- curl::multi_download(chosen_url, destfiles = temp_path, resume = TRUE)
if (isTRUE(download_result$success) && download_result$status_code %in% c(200, 206)) break
if (attempts >= 5) {
stop(
"download failed after ", attempts, " attempts (last status: ",
download_result$status_code, "): ", download_result$error) }
}
file.rename(temp_path, file_path)
"downloaded"
}, error = function(e) {
warning("[", name, "] Download failed: ", conditionMessage(e))
Expand Down
Loading
Loading