| Title: | CrashAPI |
|---|---|
| Description: | Get Fatality Analysis Reporting System (FARS) data with the FARS API from the U.S. National Highway Traffic Safety Administration (NHTSA). |
| Authors: | Eli Pousson [aut, cre] (ORCID: <https://orcid.org/0000-0001-8280-1706>), Kyle Walker [cph] (Author of tigris helper functions bundled with crashapi (see tigris-utils.R).) |
| Maintainer: | Eli Pousson <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.2 |
| Built: | 2026-10-12 06:17:38 UTC |
| Source: | https://github.com/elipousson/crashapi |
This index include identified data from cities, counties, or regional entities in 43 of 50 U.S. states. Statewide data sources are included from 33 states. In 4 states (NE, OH, ME, and CT), the only identified statewide data sources allow limited access through a web-based public query form. In 1 state (MN), data only available through restricted access mapping/query tool. Not all statewide data sources include all crashes (some include only cyclist/pedestrian crashes or fatal crashes) and the structure and format of the crash data provided varies considerably.
crash_data_indexcrash_data_index
A data frame with 75 rows and 22 variables:
nameName of data set from provider.
levelGeographic scope/level (e.g. city, county, region, state, national)
cityCity name
countyCounty name
regionlogical COLUMN_DESCRIPTION
state_nameU.S. state name
state_abbU.S. state abbreviation
info_urlInformational URL (e.g. informational page about file download options)
data_urlData URL (e.g. direct link to ArcGIS FeatureServer layer)
formatData format (e.g. Socrata, CKAN, ArcGIS MapServer, etc.)
statewide_ynYes for data with statewide geographic scope; NA for data from city, county, or regional level providers
batch_download_ynYes for data where batch download is possible
start_yearEarliest year for crashes in dataset
end_yearLatest year for crashes in dataset
publisherAgency/organization responsible for publishing the data online
descriptionDescription of the dataset from provider
bike_ped_onlyYes for data that only includes bike/ped involved crashes (common for Vision Zero programs)
rolling_windowDescription of rolling time window if data is only available within a rolling window
fatal_severe_onlyYes for data that only includes fatal/severe crashes (common for Vision Zero programs)
date_noteNote on the dates for the crash data
updatesInformation on update schedule if available
noteGeneral notes
This index was compiled by Eli Pousson between October 2021 and February 2022 with additional contributions from Mae Hanzlik.
Added: March 27 2022 Updated: June 05 2022
Corrections, updates, or additional sources should be added to this public Google Sheet: https://docs.google.com/spreadsheets/d/1rmn6GbHNkfWLLDEEmA87iuy2yHdh7hBybCTZiQJEY0k/edit?usp=sharing
decode_fars() adds a column with decoded values (e.g. INJ_SEVNAME for
INJ_SEV) after each coded variable in a FARS or CRSS data table, using the
value labels from fars_value_labels() for the year of each row. Variables
that already have a decoded column (like the …NAME columns in data from
the CrashAPI or FARS zipped CSV files from 2015 onwards) are not changed
unless overwrite = TRUE.
decode_fars( x, table, year = NULL, decode = c("names", "replace", "labelled"), source = c("FARS", "CRSS"), suffix = "NAME", overwrite = FALSE )decode_fars( x, table, year = NULL, decode = c("names", "replace", "labelled"), source = c("FARS", "CRSS"), suffix = "NAME", overwrite = FALSE )
x |
A data frame with a FARS or CRSS data table, e.g. from
|
table |
Name of the FARS or CRSS data table (e.g. "accident", "person", or "vehicle"). |
year |
Year of the data. If |
decode |
How to decode values:
|
source |
Data source: "FARS" (default) or "CRSS". |
suffix |
Suffix for the names of the decoded columns if |
overwrite |
If |
get_fars() uses decode_fars() to add decoded columns to data from zipped
FARS data files before 2015.
x with additional columns of decoded values (decode = "names"), factors of decoded values (decode = "replace"), or labelled
vectors (decode = "labelled").
person <- data.frame(CASEYEAR = c(1985, 2024), INJ_SEV = c(3, 3)) decode_fars(person, table = "person") decode_fars(person, table = "person", decode = "replace")person <- data.frame(CASEYEAR = c(1985, 2024), INJ_SEV = c(3, 3)) decode_fars(person, table = "person") decode_fars(person, table = "person", decode = "replace")
FARS-related terms defined by the National Highway Traffic Safety Administration based on ANSI D16.1-1996: Manual on Classification of Motor Vehicle Traffic Accidents.
fars_termsfars_terms
A data frame with 66 rows and 2 variables:
termcharacter Term
definitioncharacter Term definition
Added: October 25 2021 Updated: October 25 2021
fars_value_labels() returns the value labels (the decoded value for each
code) for variables in the FARS or CRSS data files by year. The value labels
are built from the SAS format programs and data files that NHTSA publishes
with the zipped SAS data for each year (see data-raw/fars_value_labels.R).
fars_value_labels( year = NULL, table = NULL, variable = NULL, source = c("FARS", "CRSS") )fars_value_labels( year = NULL, table = NULL, variable = NULL, source = c("FARS", "CRSS") )
year |
One or more years. If |
table |
One or more FARS or CRSS data table names (e.g. "accident",
"person", or "vehicle"). Not case sensitive. If |
variable |
One or more variable names (e.g. "INJ_SEV"). Not case
sensitive. If |
source |
Data source: "FARS" (default) or "CRSS". |
Value labels change over time, so the same code can have a different label
in different years. For example, the INJ_SEV code 3 is labelled
"Incapacitating" in early FARS data and "Suspected Serious Injury (A)" in
recent years.
The CrashAPI and FARS zipped CSV files from 2015 onwards include …NAME
columns with decoded values. Use decode_fars() to add these columns to
older FARS data or CRSS data.
Labels from the SAS formats can differ slightly in wording from the …NAME
columns in the CSV files (e.g. "Curve - Right" instead of "Curve Right"
for VALIGN). A few variables use SAS formats that NHTSA doesn't publish
(e.g. a state variable in some 2006-2015 tables) and are not included.
Value labels for the FARS vPIC variables (e.g. VPICMAKE and VPICMODEL,
used from 2020 onwards) are not included since FARS data already includes
…NAME columns for these variables; they are included for CRSS data.
A data frame with columns source, year, table, variable,
format (the SAS format name, without the year), code (as written in the SAS format, e.g.
"01"), code_min and code_max (numeric codes or ranges), and value
(the label).
# Injury severity labels for the person table in 1985 and 2024 fars_value_labels( year = c(1985, 2024), table = "person", variable = "INJ_SEV" )# Injury severity labels for the person table in 1985 and 2024 fars_value_labels( year = c(1985, 2024), table = "person", variable = "INJ_SEV" )
fars_variables() returns the variables in each FARS or CRSS data table by
year with the variable label and SAS format name from the SAS data files
that NHTSA publishes with the zipped SAS data for each year (see
data-raw/fars_value_labels.R). Variable labels can change over time and
include variables that are not in fars_vars_labels (e.g. variables added
in recent years or only used in CRSS).
fars_variables( year = NULL, table = NULL, variable = NULL, source = c("FARS", "CRSS") )fars_variables( year = NULL, table = NULL, variable = NULL, source = c("FARS", "CRSS") )
year |
One or more years. If |
table |
One or more FARS or CRSS data table names (e.g. "accident",
"person", or "vehicle"). Not case sensitive. If |
variable |
One or more variable names (e.g. "INJ_SEV"). Not case
sensitive. If |
source |
Data source: "FARS" (default) or "CRSS". |
A data frame with columns source, year, table, variable,
label (the variable label), and format (the SAS format name without
the year, or NA for variables without value labels).
fars_variables(year = 2024, table = "person", variable = c("AGE", "INJ_SEV"))fars_variables(year = 2024, table = "person", variable = c("AGE", "INJ_SEV"))
By default, this function returns the list of variables for
the data year specified. If var is "make", "model", or "bodytype", the
function returns a list of variable attributes for the specified variable
name or attributes for make model and body type specified in the FARS
dataset.
fars_vars( year = getOption("crashapi.year", 2024), var = NULL, make = NULL, model = NULL )fars_vars( year = getOption("crashapi.year", 2024), var = NULL, make = NULL, model = NULL )
year |
One or more case years between 2010 and 2024. If more than one
year is provided, the results for each year are combined. Ignored if |
var |
Default NULL. Supported values are "make", "model", and "bodytype". Using the var parameter returns variable attributes for the specified variable name or attributes for make model and body type specified in the dataset. |
make |
Integer. Make ID number. Required to return variables for "model"
and "bodytype". Get a list of make ID numbers using the "make" var for the
selected year, e.g. |
model |
Integer. Model ID number. Required to return variables for
"bodytype". Get a list of model ID numbers using the "model" var for the
selected year with a valid make ID number, e.g. |
A data frame with a year column (except when var is
"bodytype").
head(fars_vars(year = 2022, var = "make"), 5) head(fars_vars(year = 2022, var = "model", make = 12), 5) fars_vars(year = 2022, var = "bodytype", make = 12, model = 37)head(fars_vars(year = 2022, var = "make"), 5) head(fars_vars(year = 2022, var = "model", make = 12), 5) fars_vars(year = 2022, var = "bodytype", make = 12, model = 37)
A table of FARS table variable names extracted from the Fatality Analysis Reporting System (FARS) Analytical User's Manual, 1975-2019, documentation of the SAS format data files.
fars_vars_labelsfars_vars_labels
A data frame with 749 rows and 15 variables:
namecharacter Variable name
labelcharacter Variable label
orderdouble Sort order
data_filecharacter SAS data file name
data_file_iddouble SAS data file ID
file_idcharacter File ID
keylogical Indicator for key variables
locationdouble Location in SAS data file
mmuc_equivalentlogical Equivalent term in MMUC (placeholder)
discontinuedlogical Indicator for discontinued variables
api_onlylogical Indicator for variables only used by API
apicharacter Name(s) of corresponding CrashAPI service (e.g. "Details" for GetCaseDetails or "FARS data" for GetFARSData)
name_varlogical Indicator for "NAME" variable returned by API
nmShort version of the variable name
api_list_collogical Indicator for list columns returned by API
This table is used for column order, CrashAPI metadata, and variable labels
for columns that are only returned by the CrashAPI. Use fars_variables()
for complete, year-specific variable labels from the SAS data files that
NHTSA publishes for each year.
The source data is installed with the package as a CSV file
(system.file("extdata", "fars_vars_labels.csv", package = "crashapi"))
with column definitions in fars_vars_labels_definitions.csv.
Added: January 31 2022 Updated: March 27 2022
Reorder columns to match the order documented in Fatality Analysis Reporting System (FARS) Analytical User's Manual, 1975-2019, convert coordinate and count columns to numeric and integer values, and append derived columns for date, time, and datetime. Column names are kept as returned by the API.
format_crashes(x, details = TRUE, var_labels = c("attribute", "none"))format_crashes(x, details = TRUE, var_labels = c("attribute", "none"))
x |
Data frame with crash data. |
details |
If |
var_labels |
How to add variable labels from fars_vars_labels:
"attribute" (default) adds a |
The Crash Report Sampling System (CRSS)
is a national sample of police-reported motor vehicle crashes of all
severities, from minor property damage to fatal crashes, and replaced the
General Estimates System (GES) in 2016. This function is similar to
get_fars_zip() to download CRSS files directly from the NHTSA downloads
site. If read is TRUE, the function returns a list containing data frames
for each table available in the selected year.
get_crss_zip( year = getOption("crashapi.year", 2024), format = "csv", path = NULL, aux = FALSE, read = TRUE, geometry = FALSE, overwrite = FALSE, keep_files = FALSE, var_labels = c("attribute", "none") )get_crss_zip( year = getOption("crashapi.year", 2024), format = "csv", path = NULL, aux = FALSE, read = TRUE, geometry = FALSE, overwrite = FALSE, keep_files = FALSE, var_labels = c("attribute", "none") )
year |
One or more years of data from 2016 to 2024. Each year is
downloaded separately and, if |
format |
Format of zipped data tables ('csv' or 'sas'). Default: 'csv'.
|
path |
Directory for downloaded and cached files. If |
aux |
If |
read |
If |
geometry |
Not supported for CRSS data, which does not include
coordinates. If |
overwrite |
If |
keep_files |
If |
var_labels |
How to add variable labels: "attribute" (default) adds a
|
CRSS is a sample, so national estimates should use the sampling weight
(WEIGHT) and survey design variables (e.g. PSU_VAR and PSUSTRAT) as
described in the CRSS Analytical User's Manual. CRSS data does not include
crash locations beyond broad geographic categories (e.g. REGION and
URBANICITY).
Zipped CSV files are converted to parquet files and cached in a folder
named after the zip file within path (by default, the user cache directory
from tools::R_user_dir()), and the zip and CSV files are removed unless
keep_files = TRUE. Later calls read the cached parquet files without
downloading the data again unless overwrite = TRUE.
If read = TRUE, a list of data frames with one item for each
table (with the accident table converted to an sf object if geometry = TRUE). If read = FALSE, the cached parquet file paths named by table (or
the zip file path if format = "sas") invisibly. If more than one year is
provided, returns a list named by year.
get_fars() returns a FARS data table (e.g. accident, person, or vehicle)
for one or more states, an optional county, and one or more years, using
the CrashAPI or the zipped data files from the NHTSA downloads site:
get_fars( state = NULL, year = getOption("crashapi.year", 2024), type = "accident", county = NULL, source = c("auto", "api", "zip"), ..., geometry = FALSE, crs = NULL, decode = c("names", "replace", "labelled", "none"), var_labels = c("attribute", "none") )get_fars( state = NULL, year = getOption("crashapi.year", 2024), type = "accident", county = NULL, source = c("auto", "api", "zip"), ..., geometry = FALSE, crs = NULL, decode = c("names", "replace", "labelled", "none"), var_labels = c("attribute", "none") )
state |
One or more state names, abbreviations, or FIPS numbers. If
|
year |
One or more years from 1975 to 2024 (or from 2010 for the
CrashAPI). The minimum and maximum values are used as the start and end
year, with a message if |
type |
Name of the FARS data table, e.g. "accident" (default),
"person", or "vehicle". Lowercase or uppercase values are permitted. The
available tables vary by year and source; see |
county |
County name or FIPS number. Requires a single |
source |
Source for the data: "auto" (default), "api" for the CrashAPI, or "zip" for zipped data files. |
... |
Additional parameters passed to |
geometry |
If |
crs |
Coordinate reference system to use if |
decode |
How to decode coded values using |
var_labels |
How to add variable labels from fars_vars_labels:
"attribute" (default) adds a |
With source = "auto" (default), data for a state from 2010 onwards
comes from the CrashAPI with get_fars_year(). National data (state = NULL), data for Puerto Rico (state = "PR"), and data before 2010 comes
from zipped data files with get_fars_zip(), which are converted to parquet
files and cached so later calls do not download the data again.
Data from zipped files is filtered to the requested states and, if
needed, a CASEYEAR column is added so the data matches the CrashAPI.
If county is provided, tables with a COUNTY column (accident and
person) are filtered by county and other tables are filtered to crashes in
the county from the accident table (matching ST_CASE and CASEYEAR).
Use get_fars_crashes(), get_fars_cases(), get_fars_crash_list(), or
get_fars_summary() to access other CrashAPI endpoints.
A data frame, or an sf object if geometry = TRUE. If tables for
multiple years from zipped data files can't be combined, a list of data
frames named by year.
# Person table for Maryland from the CrashAPI head(get_fars(state = "MD", year = 2022, type = "person"), 5) # Accident table for Baltimore City get_fars(state = "MD", county = "Baltimore city", year = 2022) # National accident table from the zipped data files get_fars(year = 2024)# Person table for Maryland from the CrashAPI head(get_fars(state = "MD", year = 2022, type = "person"), 5) # Accident table for Baltimore City get_fars(state = "MD", county = "Baltimore city", year = 2022) # National accident table from the zipped data files get_fars(year = 2024)
This function returns a list of people involved in fatal crashes that match a specific age, sex, seat position, and injury severity using the CrashAPI GetCrashesByPerson endpoint. The returned data has one row for each person.
get_fars_crash_persons( state, age, sex, seat, injury, year = getOption("crashapi.year", 2024), var_labels = c("attribute", "none") )get_fars_crash_persons( state, age, sex, seat, injury, year = getOption("crashapi.year", 2024), var_labels = c("attribute", "none") )
state |
Required. State name, abbreviation, or FIPS number. |
age |
Required. Age in years. |
sex |
Required. Code or name for the person's sex: 1 ("Male"), 2 ("Female"), 8 ("Not Reported"), or 9 ("Reported as Unknown"). "m", "f", and "unknown" are also accepted. |
seat |
Required. Code or name for the person's seat position, e.g. 11 or "Front Seat, Left Side" ("front left" is also accepted). Use 0 or "Not a Motor Vehicle Occupant" for non-occupants. See the FARS Analytical User's Manual for all seat position codes. |
injury |
Required. Code or name for the person's injury severity: 0 ("No Apparent Injury (O)"), 1 ("Possible Injury (C)"), 2 ("Suspected Minor Injury (B)"), 3 ("Suspected Serious Injury (A)"), 4 ("Fatal Injury (K)"), 5 ("Injured, Severity Unknown"), 6 ("Died Prior to Crash"), or 9 ("Unknown/Not Reported"). Short names (e.g. "fatal") and KABCO letters (e.g. "K") are also accepted. |
year |
numeric vector. One or more years from 2010 to 2024. The minimum
and maximum values are used as the start and end year. Defaults to
|
var_labels |
How to add variable labels from fars_vars_labels:
"attribute" (default) adds a |
NHTSA's documentation says this endpoint accepts "one or more" occupant
details for age, sex, seat position, and injury severity. However, testing in
October 2026 found that the API does not behave this way: the API returns an
error (HTTP 404) unless all four are provided, an error message if any are
blank, and only returns people who match all four values exactly. For this
reason, age, sex, seat, and injury are all required.
The endpoint's includeOccupants and includeNonOccupants parameters are
not supported since the required seat position already determines whether
occupants or non-occupants are returned (use seat = 0 for people who were
not motor vehicle occupants).
To find people using other criteria (e.g. a range of ages or any injury
severity), download the person table with get_fars_year() using type = "person" and filter the data.
# Fatally injured 30 year old female drivers in Maryland in 2022 get_fars_crash_persons( state = "MD", age = 30, sex = "female", seat = "front left", injury = "fatal", year = 2022 )# Fatally injured 30 year old female drivers in Maryland in 2022 get_fars_crash_persons( state = "MD", age = 30, sex = "female", seat = "front left", injury = "fatal", year = 2022 )
This function returns a list of fatal crashes involving a
specific vehicle make, model, model year, and body type using the CrashAPI
GetCrashesByVehicle endpoint. The make, model, and body type can be names
or ID numbers matching the options returned by fars_vars(). Names are
converted to ID numbers for use in the API query.
get_fars_crash_vehicles( state, make, model, model_year, body_type, year = getOption("crashapi.year", 2024), var_labels = c("attribute", "none") )get_fars_crash_vehicles( state, make, model, model_year, body_type, year = getOption("crashapi.year", 2024), var_labels = c("attribute", "none") )
state |
Required. State name, abbreviation, or FIPS number. |
make |
Required. Make name or ID, e.g. "Ford" or 12. Valid options are
returned by |
model |
Required. Model name or ID. Valid options are returned by
|
model_year |
Required. Vehicle model year. |
body_type |
Required. Body type name or ID. Valid options are returned
by |
year |
numeric vector. One or more years from 2010 to 2024. The minimum
and maximum values are used as the start and end year. Defaults to
|
var_labels |
How to add variable labels from fars_vars_labels:
"attribute" (default) adds a |
NHTSA's documentation says this endpoint accepts "one or more" vehicle
details for make, model, model year, and body type. However, testing in
October 2026 found that the API does not behave this way: the API returns an
error (HTTP 404) unless all four are provided and an error message if any
are blank. For this reason, make, model, model_year, and body_type
are all required.
To find crashes using other vehicle criteria, download the vehicle table
with get_fars_year() using type = "vehicle" and filter the data.
get_fars_crash_vehicles( state = "CA", make = "Ford", model = 37, model_year = 2012, body_type = 4, year = 2022 )get_fars_crash_vehicles( state = "CA", make = "Ford", model = 37, model_year = 2012, body_type = 4, year = 2022 )
These functions access specific endpoints of DOT NHTSA's CrashAPI:
get_fars_crashes returns a list of fatal crashes in a county.
get_fars_cases returns details for one or more fatal crashes by case
number.
get_fars_crash_list returns a list of fatal crashes that have occurred
in one or more states with a range of vehicles involved.
get_fars_summary provides a count of crashes and fatalities by year for
a state.
get_fars_year provides a FARS data table for a state.
Both get_fars_crash_list and get_fars_crashes limit the returned data
to 5000 records so consider limiting the range of years requested if data
exceeds that threshold.
Use get_fars() to get FARS data tables for any state, county, or year
(including national data and years before 2010) from the CrashAPI or the
NHTSA data downloads site.
get_fars_crashes( state, county, year = getOption("crashapi.year", 2024), details = FALSE, geometry = FALSE, crs = NULL, var_labels = c("attribute", "none") ) get_fars_cases( state, cases, year = getOption("crashapi.year", 2024), details = FALSE, geometry = FALSE, crs = NULL, var_labels = c("attribute", "none") ) get_fars_crash_list( state, year = getOption("crashapi.year", 2024), vehicles = c(1, 50), var_labels = c("attribute", "none") ) get_fars_summary( state, year = getOption("crashapi.year", 2024), var_labels = c("attribute", "none") ) get_fars_year( state, year = getOption("crashapi.year", 2024), type = "accident", format = "json", path = NULL, geometry = FALSE, crs = NULL, download = FALSE, var_labels = c("attribute", "none"), call = caller_env() )get_fars_crashes( state, county, year = getOption("crashapi.year", 2024), details = FALSE, geometry = FALSE, crs = NULL, var_labels = c("attribute", "none") ) get_fars_cases( state, cases, year = getOption("crashapi.year", 2024), details = FALSE, geometry = FALSE, crs = NULL, var_labels = c("attribute", "none") ) get_fars_crash_list( state, year = getOption("crashapi.year", 2024), vehicles = c(1, 50), var_labels = c("attribute", "none") ) get_fars_summary( state, year = getOption("crashapi.year", 2024), var_labels = c("attribute", "none") ) get_fars_year( state, year = getOption("crashapi.year", 2024), type = "accident", format = "json", path = NULL, geometry = FALSE, crs = NULL, download = FALSE, var_labels = c("attribute", "none"), call = caller_env() )
state |
Required. State name, abbreviation, or FIPS number.
|
county |
County name or FIPS number. Required for |
year |
numeric vector. One or more years. For |
details |
For |
geometry |
If |
crs |
Coordinate reference system to return for |
var_labels |
How to add variable labels from fars_vars_labels:
"attribute" (default) adds a |
cases |
One or more FARS case numbers. Required for |
vehicles |
numeric vector with the minimum and maximum number of
vehicles, e.g. c(1, 2) for minimum of 1 vehicle and maximum of 2. Required
for |
type |
Name of the FARS data table. Supported values include "ACCIDENT",
"CEVENT", "DAMAGE", "DISTRACT", "DRIMPAIR", "DRUGS", "FACTOR",
"MANEUVER", "NMCRASH", "NMIMPAIR", "NMPRIOR", "PARKWORK", "PBTYPE",
"PERSON", "SAFETYEQ", "VEHICLE", "VEVENT", "VINDECODE", "VINDERIVED",
"VIOLATION", "VISION", and "VSOE". "TRAILERVINDERIVED" is supported for
2016 onwards, "NMDISTRACT" and "RACE" for 2019 onwards, and "CRASHRF",
"DRIVERRF", "PERSONRF", "PVEHICLESF", "VEHICLESF", and "WEATHER" for
2020 onwards for |
format |
Format to request from the CrashAPI for |
path |
Directory to save the file if |
download |
logical. If |
call |
The execution environment of a currently
running function, e.g. |
head(get_fars_crashes(state = "MD", county = "Baltimore city"), 5) get_fars_cases(state = "MD", cases = "240274") get_fars_crash_list(state = "MD", vehicles = 5) get_fars_summary(state = "MD") head(get_fars_year(state = "MD", type = "PERSON"), 5)head(get_fars_crashes(state = "MD", county = "Baltimore city"), 5) get_fars_cases(state = "MD", cases = "240274") get_fars_crash_list(state = "MD", vehicles = 5) get_fars_summary(state = "MD") head(get_fars_year(state = "MD", type = "PERSON"), 5)
This function provides an alternative to get_fars_year() that downloads
files directly from the NHTSA downloads site. If read is TRUE, the
function returns a list containing data frames for each table available in
the selected year. If geometry is TRUE, the accident table is converted
to an sf object.
get_fars_zip( year = getOption("crashapi.year", 2024), format = "csv", path = NULL, pr = FALSE, aux = FALSE, read = TRUE, geometry = FALSE, overwrite = FALSE, keep_files = FALSE, var_labels = c("attribute", "none") )get_fars_zip( year = getOption("crashapi.year", 2024), format = "csv", path = NULL, pr = FALSE, aux = FALSE, read = TRUE, geometry = FALSE, overwrite = FALSE, keep_files = FALSE, var_labels = c("attribute", "none") )
year |
One or more years of data from 1975 to 2024. Each year is
downloaded separately and, if |
format |
Format of zipped data tables ('csv' or 'sas'). Default: 'csv'.
|
path |
Directory for downloaded and cached files. If |
pr |
If |
aux |
If |
read |
If |
geometry |
If |
overwrite |
If |
keep_files |
If |
var_labels |
How to add variable labels from fars_vars_labels:
"attribute" (default) adds a |
Zipped CSV files are converted to parquet files and cached in a folder
named after the zip file within path (by default, the user cache directory
from tools::R_user_dir()), and the zip and CSV files are removed unless
keep_files = TRUE. Later calls read the cached parquet files without
downloading the data again unless overwrite = TRUE.
If read = TRUE, a list of data frames with one item for each
table (with the accident table converted to an sf object if geometry = TRUE). If read = FALSE, the cached parquet file paths named by table (or
the zip file path if format = "sas") invisibly. If more than one year is
provided, returns a list named by year.
A collection of the 73 unique codes identified as simple codes: https://release.niem.gov/niem/codes/mmucc/4.1/mmucc.xsd
See the MMUCC Guideline Fifth Edition (2017) for more information: https://crashstats.nhtsa.dot.gov/Api/Public/Publication/812433
About MMUC from NHTSA: https://www.nhtsa.gov/mmucc-1
To encourage greater uniformity, the National Highway Traffic Safety Administration (NHTSA) and the Governors Highway Safety Association (GHSA) cooperatively developed a voluntary data collection guideline in 1998. The MMUCC guideline identifies a minimum set of motor vehicle crash data elements and their attributes that States should consider collecting and including in their State crash data system.
The MMUCC 5th Edition is the result of an 18-month collaboration between NHTSA, the Federal Highway Administration (FHWA), the Federal Motor Carrier Safety Administration (FMCSA), the National Transportation Safety Board (NTSB), the GHSA, and subject matter experts from State DOTs, local law enforcement, emergency medical services, safety organizations, industry partners, and academia. The traffic records community and general public also contributed through external forums (Federal Register) and at the 2016 Traffic Records Forum.
Added: March 26 2022
Updated: March 26 2022
mmucc_codesmmucc_codes
A data frame with 700 rows and 6 variables:
codeAttribute code
nameAttribute code name
typeAttribute code type
definitionCode definition
restriction_idRestriction id number
restrictionRestriction value
An updated utility function using the httr2 package to read data from the CrashAPI using the API URL templates listed on the NHSTA website: https://crashviewer.nhtsa.dot.gov/crashviewer/CrashAPI
read_crashapi( url = "https://crashviewer.nhtsa.dot.gov/crashviewer/CrashAPI", data = "crashes", type = NULL, format = "json", results = TRUE, ..., cookie_file = "crashapi.cookies", call = caller_env() )read_crashapi( url = "https://crashviewer.nhtsa.dot.gov/crashviewer/CrashAPI", data = "crashes", type = NULL, format = "json", results = TRUE, ..., cookie_file = "crashapi.cookies", call = caller_env() )
url |
Base url for CrashAPI. |
data |
Data (crashes, analytics, or fars), Default: 'crashes' |
type |
Type of API to use, Default: |
format |
Format to return, Default: 'json' |
results |
If |
... |
Additional parameters used in template (varies by type). |
cookie_file |
File name passed to |
call |
The execution environment of a currently
running function, e.g. |
Data frame with requested data or a formatted url (if results = FALSE)