Skip to content

Commit 0804afb

Browse files
Merge pull request #62 from UI-Research/disaster-dollar-database
added function to source disaster dollar database data
2 parents 22ef018 + e417d61 commit 0804afb

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

R/get_disaster_dollar_database.R

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#' @title Get Disaster Dollar Database Data
2+
#' @details These data are sourced from: https://carnegieendowment.org/features/disaster-dollar-database. The data returned from this function are unchanged, though some columns have been renamed slightly for clarity and consistency.
3+
#'
4+
#' @param file_path The path (on Box) to the file containing the raw data.
5+
#'
6+
#' @returns A dataframe comprising disaster-level observations with financial assistance metrics from FEMA's Individual and Households Program (IHP), Public Assistance (PA), HUD's Community Development Block Grant Disaster Recovery (CDBG-DR), and SBA disaster loans.
7+
#' @export
8+
#'
9+
#' @examples
10+
#' \dontrun{
11+
#' get_disaster_dollar_database()
12+
#' }
13+
14+
get_disaster_dollar_database = function(
15+
file_path = file.path(get_box_path(), "hazards", "carnegie-endowment", "disaster_dollar_database_2025_11_19.csv")) {
16+
17+
## is the file path valid/accessible?
18+
if (!file.exists(file_path)) {
19+
stop(stringr::str_c(
20+
"The path to the dataset does not point to a valid file. ",
21+
"Please ensure there is a file located at this path: ", file_path, ".")) }
22+
23+
df_raw = readr::read_csv(file_path) |>
24+
dplyr::select(
25+
year,
26+
event_name = event,
27+
incident_number,
28+
incident_start,
29+
incident_end,
30+
declaration_date,
31+
state_abbreviation = state,
32+
incident_type,
33+
ihp_applications_valid = valid_ihp_applications,
34+
ihp_applications_approved = eligible_ihp_applications,
35+
ihp_eligibility_rate,
36+
ihp_allocated_amount_total = ihp_total,
37+
ihp_allocated_amount_average = ihp_average_award,
38+
pa_allocated_amount_total = pa_total,
39+
pa_projects_count,
40+
cdbg_df_allocated_amount_total = cdbg_dr_allocation,
41+
sba_loan_amount_approved_total = sba_total_approved_loan_amount)
42+
43+
message(stringr::str_c(
44+
"The unit of observation is: disaster event. ",
45+
"Each observation represents a single declared disaster event with associated financial assistance metrics from multiple federal programs."))
46+
47+
return(df_raw)
48+
49+
}
50+
51+
utils::globalVariables(c(
52+
"year", "event", "incident_number", "incident_start", "incident_end",
53+
"declaration_date", "state", "incident_type", "valid_ihp_applications",
54+
"eligible_ihp_applications", "ihp_eligibility_rate", "ihp_total",
55+
"ihp_average_award", "pa_total", "pa_projects_count", "cdbg_dr_allocation",
56+
"sba_total_approved_loan_amount"))

0 commit comments

Comments
 (0)