Package 'rfema'

Title: Access the openFEMA API
Description: `rfema` allows users to access The Federal Emergency Management Agency's (FEMA) publicly available data through their API. The package provides a set of functions to easily navigate and access data from the National Flood Insurance Program along with FEMA's various disaster aid programs, including the Hazard Mitigation Grant Program, the Public Assistance Grant Program, and the Individual Assistance Grant Program.
Authors: Dylan Turner [aut, cre] , François Michonneau [rev, ctb] (reviewed the package for rOpenSci and patched several bugs in the prelease code, see https://github.com/ropensci/software-review/issues/484.), Marcus Beck [rev, ctb] (reviewed the package for rOpenSci, see https://github.com/ropensci/software-review/issues/484.)
Maintainer: Dylan Turner <[email protected]>
License: MIT + file LICENSE
Version: 1.0.0
Built: 2024-08-29 23:10:03 UTC
Source: https://github.com/ropensci/rfema

Help Index


Bulk download full open FEMA data sets as .csv files

Description

For large data requests, it can sometimes be more practical (and quicker) to download and work with the entire data set. This function provides an easy way to download any of FEMA's data sets in its entirety and save it locally as a csv file.

Usage

bulk_dl(data_set, output_dir = NULL, file_name = NULL, size_warning = TRUE)

Arguments

data_set

A character string indicating the name of the data set to download

output_dir

An optional character string indicating the directory (defaults to working directory)

file_name

An optional character string indicating the file name (defaults to data set name with time stamp)

size_warning

A logical indicating whether to issue a warning before proceeding with downloading a large file (default is TRUE)

Value

Returns a downloaded csv file of the data set to the specified output directory.

Examples

## Not run: 
bulk_dl("femaregions") # download the file

## End(Not run)
## Not run: 
file.remove("FemaRegions.csv") # clean up directory after file downloads

## End(Not run)

Get data fields and descriptions for a given FEMA data set

Description

Get data fields and descriptions for a given FEMA data set

Usage

fema_data_fields(data_set)

Arguments

data_set

a character string indicating the data set of interest

Value

Returns a tibble consisting of the data fields name, along with information about each data field including the data type, a description of the data field, and whether the data field is "searchable" (i.e. can it be used to filter the returned data in an API query)

Examples

## Not run: 
fema_data_fields("FimaNfipClaims")

## End(Not run)
## Not run: 
fema_data_fields("FimaNfipPolicies")

## End(Not run)

Get a tibble of available FEMA data sets

Description

Get a tibble of available FEMA data sets

Usage

fema_data_sets()

Value

Returns a tibble containing meta data about each data set available through the FEMA API. For more information see the FEMA documentation page: https://www.fema.gov/about/openfema/data-sets.

Examples

## Not run: 
fema_data_sets()

## End(Not run)

Get data from the FEMA API

Description

The function allows users to pull data directly from the FEMA API and have it returned as a data frame natively within R.The FEMA API limits a single query to 1000 records, thus for a query resulting in more than 1000 records, an iterative approach is necessary to get all of the records. The function handles this and will, by default, warn the user of how many iterations are needed to get all the records matching their query, letting the user decide choose whether to continue.

Usage

open_fema(
  data_set,
  top_n = NULL,
  filters = NULL,
  select = NULL,
  ask_before_call = TRUE,
  file_type = NULL,
  output_dir = NULL
)

Arguments

data_set

a character string indicating the data set to get data from

top_n

an optional integer value to specify the maximum number of matching records to return

filters

an optional list containing values of the data fields contained in the data set to construct filters from

select

an optional character vector to specify which data fields to return (default is to return all data fields)

ask_before_call

a logical indicating if users should be asked if they would like to proceed when an API call results in a large number of records (default is T).

file_type

an optional character string that specifies a file type to save the data as (options are "csv" and "rds"). If a file is specified, the function will not return the api call as a data frame

output_dir

an optional character string specifying the directory to save the exported file if the file_type is specified (defaults to working directory).

Value

Returns a tibble containing the data from the FEMA API.

Examples

## Not run: 
data <- open_fema(
  data_set = "fimaNfipClaims", top_n = 100,
  filters = list(countyCode = "10001")
)

## End(Not run)

Returns examples of data field values along with a description of the data field

Description

Returns examples of data field values along with a description of the data field

Usage

parameter_values(data_set = NULL, data_field = NULL, message = TRUE)

Arguments

data_set

a character vector specifying the data set

data_field

a character vector specifying the data field

message

a logical value that is TRUE by default. When TRUE, the function will return information as a console message. When set to FALSE, the function will return the same information as a tibble.

Value

returns a consoles message providing a description of the data field and several example values of the data field within the data set.

Examples

## Not run: 
parameter_values(
  data_set = "fimaNfipClaims",
  data_field = "totalBuildingInsuranceCoverage"
)

## End(Not run)

Get all valid API parameters for a given FEMA data set

Description

Get all valid API parameters for a given FEMA data set

Usage

valid_parameters(data_set = NULL)

Arguments

data_set

A character string indicating the data set to return valid parameters for

Value

Returns a tibble of parameter names that can be used to filter an API call for a given open FEMA data set

Examples

## Not run: 
valid_parameters("fimaNfipPolicies")

## End(Not run)