# install the rfema package directly from rOpenSci
install.packages("rfema", repos = "https://ropensci.r-universe.dev")
library(rfema) # load package
# store meta data for the available data sets as an object in the R environment
<- fema_data_sets()
data_sets
# use the rfema::open_fema call to extract all disaster declarations from 2005-2020 for florida
<- open_fema(data_set = "DisasterDeclarationsSummaries",
fl_disasters filters = list(declarationDate = ">= 2005-01-01", declarationDate = "<= 2021-01-01", state = "= FL")) %>%
# data cleaning
mutate(year = year(declarationDate),
month = month(declarationDate), # extract the month of the disaster declaration
county_fips = str_c(fipsStateCode, fipsCountyCode), # create a county fips code
state = "Florida")
# SAVE DATA
write_csv(df, "data/disaster_declarations.csv")
FEMA API
Please use all code samples responsibly - these are samples and likely require adjustments to work correctly for your specific needs. Read through the documentation and comments to understand any caveats or limitations of the code and/or data and follow-up with the code author or Code Library admins (code_library@urban.org) if you have questions on how to adapt the sample to your specific use case.
Purpose: This code uses the rfema
package to access FEMA disaster data through the open FEMA api in an accessible way for users who aren’t familiar with apis. Using the package allows for more tailored and efficient data pulls than doing it manually, especially when working with very large data sets. You can use the package to pull data on:
Disaster declarations
National Flood Insurance Program (NFIP)
Individual/Public assistance
Emergency management
Hazard mitigation
Misc
For a full list of available data see: https://www.fema.gov/about/openfema/data-sets
Installation: The OpenFEMA api doesn’t require a key which is nice, so all you need to do is install the rfema
package which is explained below
Data: This code pulls all FEMA disaster declarations from 2005 through 2021. There are notes in the comments about where to adjust URLs to filter for different subsets of data.
Author: Amy Rogin (May 2024)