Get Fatality Analysis Reporting System (FARS) data with the FARS API
Source:R/get_fars.R
get_fars.Rd
This function provides a convenient interface for accessing FARS
data or data summaries using a range of criteria. The api
parameter
allows you to call one of the following functions to access DOT NHTSA’s
Crash API:
get_fars_crash_list
returns a list of fatal crashes that have occurred in multiple states in one or more years.get_fars_crash_details
returns a details of a fatal crash that has occurred in a state for a single year.get_fars_crashes
a list of fatal crashes by location that have occurred throughout U.S.get_fars_summary
provides a count of injury severity that have occurred throughout U.S. including count of fatalities and crashes.get_fars_year
provides one of 20 FARS data tables for a single year. Supports downloading to a CSV or JSON file.
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.
This package also enables access to the FARS data available through the
NHTSA data downloads server in a zip format. Set api
to "zip" or use the
get_fars_zip
function to download this data.
Usage
get_fars(
year = 2021,
state,
county = NULL,
api = c("crashes", "cases", "state list", "summary count", "year dataset", "zip"),
type = NULL,
details = FALSE,
geometry = FALSE,
crs = NULL,
cases = NULL,
vehicles = NULL,
format = "json",
pr = FALSE,
path = NULL,
download = FALSE
)
get_fars_crashes(
year = 2021,
start_year,
end_year = NULL,
state,
county,
details = FALSE,
geometry = FALSE,
crs = NULL
)
get_fars_cases(
year = 2021,
state,
cases,
details = FALSE,
geometry = FALSE,
crs = NULL
)
get_fars_crash_list(
year = 2021,
start_year = NULL,
end_year = NULL,
state,
vehicles = c(1, 50)
)
get_fars_summary(year = 2021, start_year, end_year = NULL, state)
get_fars_year(
year = 2021,
type = "accident",
state,
format = "json",
path = NULL,
geometry = FALSE,
crs = NULL,
download = FALSE
)
Arguments
- year
numeric vector. Year or range with start and end year. If
api
is "details", "year dataset", or "zip" (or using theget_fars_crash_details
,get_fars_year
, orget_fars_zip
functions), a single year is required. All otherapi
options support a range with the minimum value is used as a start year and the maximum value used as a end year. Mostapi
options support the years from 2010 through the most recent year of release. "year dataset" only supports 2010 to 2017 and "zip" supports 1975 to 2021.start_year
andend_year
are ignored ifyear
is notNULL
.- state
Required. State name, abbreviation, or FIPS number.
get_fars_crash_list
supports multiple states.- county
County name or FIPS number. Required for
get_fars_crashes
.- api
character. API function to use. Supported values include "crashes", "cases", "state list", "summary count", "year dataset", and "zip". Default: "crashes".
- type
Name of the dataset or data file to download when using the "year dataset" api or
get_fars_year
. Supported values include "ACCIDENT", "CEVENT", "DAMAGE", "DISTRACT", "DRIMPAIR", "FACTOR", "MANEUVER", "NMCRASH", "NMIMPAIR", "NMPRIOR", "PARKWORK", "PBTYPE", "PERSON", "SAFETYEQ", "VEHICLE", "VEVENT VINDECODE", "VINDERIVED", "VIOLATION", "VISION", and "VSOE". Lowercase or mixed case values are permitted.- details
Type of detailed crash data to return (either "events" or "vehicles"). If
TRUE
forget_fars
orget_fars_crashes
, detailed case data (excluding event and vehicle data) is attached to the returned crash data. IfNULL
forget_fars_cases
, events and vehicle data are excluded from the returned case data. returned byget_fars_cases
. Optional forget_fars_crash_details
. Default:NULL
forget_fars_cases
;FALSE
forget_fars
andget_fars_crashes
.- geometry
If
TRUE
, return sf object. Optional forget_fars_crashes
.- crs
Coordinate reference system to return for
get_fars_crashes
ifgeometry
isTRUE
.- cases
One or more FARS case numbers. Required if
api
is "cases" or usingget_fars_cases
. Multiple case numbers can be provided.- 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
get_fars_crash_list
.- format
Default "json". "csv" is supported when using the "year dataset" api. "sas" is supporting for the "zip" api.
- pr
logical. If
TRUE
, download zip file with FARS data for Puerto Rico. No Puerto Rico data available for years 1975-1977. Default:FALSE
forget_fars_zip
only.- path
File path used if download is
TRUE
.- download
logical. If
TRUE
and theapi
is "year dataset" or "zip", download the data to a file. DefaultFALSE
.- start_year
Start year for crash reports.
- end_year
End year for crash reports.
Examples
head(get_fars_crashes(state = "MD", county = "Baltimore city"), 5)
#> CITY CITYNAME COUNTY COUNTYNAME CaseYear FATALS LATITUDE
#> 1 50 BALTIMORE 510 BALTIMORE (510) 2021 1 39.20975278
#> 2 50 BALTIMORE 510 BALTIMORE (510) 2021 1 39.29286389
#> 3 50 BALTIMORE 510 BALTIMORE (510) 2021 1 39.33980556
#> 4 0 NOT APPLICABLE 510 BALTIMORE (510) 2021 1 39.35444444
#> 5 50 BALTIMORE 510 BALTIMORE (510) 2021 1 39.26650833
#> LONGITUD STATE STATENAME ST_CASE TOTALVEHICLES TWAY_ID TWAY_ID2
#> 1 -76.539688890 24 Maryland 240058 2 SR-695
#> 2 -76.606772220 24 Maryland 240097 1 FRONT ST
#> 3 -76.647577780 24 Maryland 240103 2 I-83
#> 4 -76.680441670 24 Maryland 240116 2 MU-01022 5600HIGHGATE
#> 5 -76.597138890 24 Maryland 240117 1 I-95 RAMP
#> VE_FORMS
#> 1 1
#> 2 1
#> 3 2
#> 4 2
#> 5 1
get_fars_cases(state = "MD", cases = "240274")
#> ARR_HOUR ARR_HOURNAME ARR_MIN
#> 1 99 Unknown EMS Scene Arrival Hour 99
#> ARR_MINNAME CF1 CF1NAME CF2 CF2NAME CF3 CF3NAME CITY
#> 1 Unknown EMS Scene Arrival Minutes NA NA NA NA NA NA 0
#> CITYNAME COUNTY COUNTYNAME CaseYear
#> 1 NOT APPLICABLE 33 PRINCE GEORGE`S (33) 2021
#> CrashRFs DAY DAY_WEEK DAY_WEEKNAME DRUNK_DR
#> 1 0, None, 2021, 24, MD, Maryland, 240274 16 2 Monday NA
#> FATALS FUNC_SYS FUNC_SYSNAME HARM_EV HARM_EVNAME
#> 1 1 3 Principal Arterial - Other 12 Motor Vehicle In-Transport
#> HOSP_HR HOSP_HRNAME HOSP_MN HOSP_MNNAME HOUR
#> 1 99 Unknown 99 Unknown EMS Hospital Arrival Time 14
#> HOURNAME LATITUDE LATITUDENAME LGT_COND LGT_CONDNAME LONGITUD
#> 1 2:00pm-2:59pm 39.05090278 39.05090278 1 Daylight -76.897219440
#> LONGITUDNAME MAN_COLL MAN_COLLNAME MILEPT MILEPTNAME MINUTE MINUTENAME MONTH
#> 1 -76.897219440 6 Angle 93 93 38 38 8
#> MonthName NHS NHSNAME NMDrugs NMPersonRF NMRace NOT_HOUR
#> 1 August 1 This section IS ON the NHS NA NA NA 99
#> NOT_HOURNAME NOT_MIN NOT_MINNAME NPersons NmCrashes NmDistract NmImpairs
#> 1 Unknown 99 Unknown NA NA NA NA
#> NmPriors PEDS PERMVIT PERNOTMVIT PERSONS PVH_INVL ParkWorks PbTypes RAIL
#> 1 NA 0 4 0 4 0 NA NA 0000000
#> RAILNAME RD_OWNER RD_OWNERNAME RELJCT1 RELJCT1NAME RELJCT2
#> 1 Not Applicable 1 State Highway Agency 0 No 2
#> RELJCT2NAME REL_ROAD REL_ROADNAME ROAD_FNC ROAD_FNCNAME ROUTE ROUTENAME
#> 1 Intersection 1 On Roadway NA NA 2 U.S. Highway
#> RUR_URB RUR_URBNAME SCH_BUS SCH_BUSNAME SP_JUR SP_JURNAME
#> 1 2 Urban 0 No 0 No Special Jurisdiction
#> STATENAME ST_CASE SafetyEQs State TWAY_ID TWAY_ID2 TYP_INT TYP_INTNAME
#> 1 Maryland 240274 NA 24 US-1 CR-10 3 T-Intersection
#> VE_FORMS VE_TOTAL WEATHER WEATHER1 WEATHER1NAME WEATHER2 WEATHER2NAME
#> 1 3 3 98 NA NA NA NA
#> WEATHERNAME WRK_ZONE WRK_ZONENAME
#> 1 Not Reported 0 None
#> Weathers YEAR
#> 1 2021, 24, MD, Maryland, 240274, 98, Not Reported 2021
get_fars_crash_list(state = "MD", vehicles = 5)
#> CountyName CrashDate Fatals Peds Persons St_Case State
#> 1 BALTIMORE (5) /Date(1631903820000-0400)/ 1 0 5 240314 24
#> StateName TotalVehicles
#> 1 Maryland 5
get_fars_summary(state = "MD")
#> CaseYear CrashCounts TotalFatalCounts
#> 1 2021 522 561
head(get_fars_year(state = "MD", type = "PERSON"), 5)
#> AGE AGENAME AIR_BAG AIR_BAGNAME ALC_DET ALC_DETNAME
#> 1 74 74 Years 8 Deployed- Combination 9 Not Reported
#> 2 53 53 Years 20 Not Deployed 9 Not Reported
#> 3 24 24 Years 2 Deployed- Side (door, seatback) 9 Not Reported
#> 4 31 31 Years 97 Not a Motor Vehicle Occupant 9 Not Reported
#> 5 31 31 Years 8 Deployed- Combination 9 Not Reported
#> ALC_RES ALC_RESNAME ALC_STATUS ALC_STATUSNAME ATST_TYP ATST_TYPNAME
#> 1 110 0.110 % BAC 2 Test Given 1 Blood
#> 2 200 0.200 % BAC 2 Test Given 1 Blood
#> 3 20 0.020 % BAC 2 Test Given 1 Blood
#> 4 310 0.310 % BAC 2 Test Given 1 Blood
#> 5 996 Test Not Given 0 Test Not Given 0 Test Not Given
#> BODY_TYP BODY_TYPNAME CASEYEAR CERT_NO COUNTY COUNTYNAME DAY
#> 1 4 4-door sedan, hardtop 2021 NA 13 CARROLL (13) 2
#> 2 4 4-door sedan, hardtop 2021 NA 37 ST. MARY`S (37) 1
#> 3 4 4-door sedan, hardtop 2021 NA 27 HOWARD (27) 4
#> 4 <NA> <NA> 2021 NA 15 CECIL (15) 10
#> 5 4 4-door sedan, hardtop 2021 NA 15 CECIL (15) 10
#> DEATH_DA DEATH_DANAME DEATH_HR DEATH_HRNAME
#> 1 2 2 18 18:00-18:59
#> 2 1 1 22 22:00-22:59
#> 3 4 4 6 6:00-6:59
#> 4 10 10 22 22:00-22:59
#> 5 88 Not Applicable (Non-Fatal) 88 Not Applicable (Non-fatal)
#> DEATH_MN DEATH_MNNAME DEATH_MO DEATH_MONAME
#> 1 2 2 1 January
#> 2 9 9 1 January
#> 3 18 18 1 January
#> 4 15 15 1 January
#> 5 88 Not Applicable (Non-fatal) 88 Not Applicable (Non-Fatal)
#> DEATH_TM DEATH_YR DEATH_YRNAME DOA DOANAME DRINKING
#> 1 1802 2021 2021 7 Died at Scene 1
#> 2 2209 2021 2021 7 Died at Scene 1
#> 3 618 2021 2021 0 Not Applicable 0
#> 4 2215 2021 2021 7 Died at Scene 9
#> 5 8888 8888 Not Applicable (Non-fatal) 0 Not Applicable 0
#> DRINKINGNAME DRUGRES1 DRUGRES1NAME DRUGRES2 DRUGRES2NAME
#> 1 Yes (Alcohol Involved) NA NA NA NA
#> 2 Yes (Alcohol Involved) NA NA NA NA
#> 3 No (Alcohol Not Involved) NA NA NA NA
#> 4 Reported as Unknown NA NA NA NA
#> 5 No (Alcohol Not Involved) NA NA NA NA
#> DRUGRES3 DRUGRES3NAME DRUGS DRUGSNAME DRUGTST1 DRUGTST1NAME
#> 1 NA NA 8 Not Reported NA NA
#> 2 NA NA 8 Not Reported NA NA
#> 3 NA NA 0 No (drugs not involved) NA NA
#> 4 NA NA 9 Reported as Unknown NA NA
#> 5 NA NA 0 No (drugs not involved) NA NA
#> DRUGTST2 DRUGTST2NAME DRUGTST3 DRUGTST3NAME DRUG_DET DRUG_DETNAME DSTATUS
#> 1 NA NA NA NA 8 Not Reported 2
#> 2 NA NA NA NA 8 Not Reported 2
#> 3 NA NA NA NA 8 Not Reported 2
#> 4 NA NA NA NA 8 Not Reported 2
#> 5 NA NA NA NA 8 Not Reported 0
#> DSTATUSNAME EJECTION EJECTIONNAME EJ_PATH
#> 1 Test Given 0 Not Ejected 0
#> 2 Test Given 2 Partially Ejected 9
#> 3 Test Given 1 Totally Ejected 9
#> 4 Test Given 8 Not Applicable 0
#> 5 Test Not Given 0 Not Ejected 0
#> EJ_PATHNAME EMER_USE EMER_USENAME EXTRICAT
#> 1 Ejection Path Not Applicable 0 Not Applicable 9
#> 2 Ejection Path Unknown 0 Not Applicable 9
#> 3 Ejection Path Unknown 0 Not Applicable 0
#> 4 Ejection Path Not Applicable <NA> <NA> 0
#> 5 Ejection Path Not Applicable 0 Not Applicable 0
#> EXTRICATNAME FIRE_EXP FIRE_EXPNAME FUNC_SYS
#> 1 Unknown 0 No or Not Reported 5
#> 2 Unknown 0 No or Not Reported 5
#> 3 Not Extricated or Not Applicable 0 No or Not Reported 3
#> 4 Not Extricated or Not Applicable <NA> <NA> 3
#> 5 Not Extricated or Not Applicable 0 No or Not Reported 3
#> FUNC_SYSNAME HARM_EV HARM_EVNAME HISPANIC
#> 1 Major Collector 52 Guardrail End 7
#> 2 Major Collector 52 Guardrail End 7
#> 3 Principal Arterial - Other 24 Guardrail Face 7
#> 4 Principal Arterial - Other 8 Pedestrian 99
#> 5 Principal Arterial - Other 8 Pedestrian 0
#> HISPANICNAME HOSPITAL HOSPITALNAME HOUR
#> 1 Non-Hispanic 0 Not Transported for Treatment 17
#> 2 Non-Hispanic 0 Not Transported for Treatment 21
#> 3 Non-Hispanic 5 EMS Ground 5
#> 4 Unknown 0 Not Transported for Treatment 22
#> 5 Not A Fatality (not Applicable) 0 Not Transported for Treatment 22
#> HOURNAME IMPACT1 IMPACT1NAME INJ_SEV INJ_SEVNAME LAG_HRS
#> 1 5:00pm-5:59pm 2 2 Clock Point 4 Fatal Injury (K) 1
#> 2 9:00pm-9:59pm 2 2 Clock Point 4 Fatal Injury (K) 0
#> 3 5:00am-5:59am 4 4 Clock Point 4 Fatal Injury (K) 0
#> 4 10:00pm-10:59pm <NA> <NA> 4 Fatal Injury (K) 0
#> 5 10:00pm-10:59pm 12 12 Clock Point 0 No Apparent Injury (O) 999
#> LAG_MINS LOCATION LOCATIONNAME
#> 1 2 0 Occupant of a Motor Vehicle
#> 2 23 0 Occupant of a Motor Vehicle
#> 3 59 0 Occupant of a Motor Vehicle
#> 4 7 11 Not at Intersection - On Roadway, Not in Marked Crosswalk
#> 5 99 0 Occupant of a Motor Vehicle
#> MAKE MAKENAME MAK_MOD MAN_COLL
#> 1 63 KIA 63034 0
#> 2 20 Chevrolet 20002 0
#> 3 58 Infiniti 58041 0
#> 4 <NA> <NA> <NA> 0
#> 5 14 Mercury 14006 0
#> MAN_COLLNAME
#> 1 The First Harmful Event was Not a Collision with a Motor Vehicle in Transport
#> 2 The First Harmful Event was Not a Collision with a Motor Vehicle in Transport
#> 3 The First Harmful Event was Not a Collision with a Motor Vehicle in Transport
#> 4 The First Harmful Event was Not a Collision with a Motor Vehicle in Transport
#> 5 The First Harmful Event was Not a Collision with a Motor Vehicle in Transport
#> MINUTE MINUTENAME MOD_YEAR MOD_YEARNAME MONTH MONTHNAME PER_NO PER_TYP
#> 1 0 0 2017 2017 1 January 1 1
#> 2 46 46 2002 2002 1 January 1 1
#> 3 19 19 2015 2015 1 January 1 1
#> 4 8 8 <NA> <NA> 1 January 1 5
#> 5 8 8 2006 2006 1 January 1 1
#> PER_TYPNAME P_SF1 P_SF1NAME P_SF2 P_SF2NAME P_SF3
#> 1 Driver of a Motor Vehicle In-Transport NA NA NA NA NA
#> 2 Driver of a Motor Vehicle In-Transport NA NA NA NA NA
#> 3 Driver of a Motor Vehicle In-Transport NA NA NA NA NA
#> 4 Pedestrian NA NA NA NA NA
#> 5 Driver of a Motor Vehicle In-Transport NA NA NA NA NA
#> P_SF3NAME RACE RACENAME REST_MIS REST_MISNAME REST_USE
#> 1 NA NA NA 0 No Indication of Misuse 3
#> 2 NA NA NA 7 None Used/Not Applicable 20
#> 3 NA NA NA 7 None Used/Not Applicable 20
#> 4 NA NA NA 8 Not a Motor Vehicle Occupant 96
#> 5 NA NA NA 0 No Indication of Misuse 3
#> REST_USENAME ROAD_FNC ROAD_FNCNAME ROLLOVER ROLLOVERNAME
#> 1 Shoulder and Lap Belt Used NA NA 0 No Rollover
#> 2 None Used/Not Applicable NA NA 0 No Rollover
#> 3 None Used/Not Applicable NA NA 0 No Rollover
#> 4 Not a Motor Vehicle Occupant NA NA <NA> <NA>
#> 5 Shoulder and Lap Belt Used NA NA 0 No Rollover
#> RUR_URB RUR_URBNAME SCH_BUS SCH_BUSNAME SEAT_POS SEAT_POSNAME
#> 1 2 Urban 0 No 11 Front Seat, Left Side
#> 2 2 Urban 0 No 11 Front Seat, Left Side
#> 3 2 Urban 0 No 11 Front Seat, Left Side
#> 4 2 Urban 0 No 0 Not a Motor Vehicle Occupant
#> 5 2 Urban 0 No 11 Front Seat, Left Side
#> SEX SEXNAME SPEC_USE SPEC_USENAME STATE STATENAME STR_VEH
#> 1 1 Male 0 No Special Use Noted 24 Maryland 0
#> 2 1 Male 0 No Special Use Noted 24 Maryland 0
#> 3 1 Male 0 No Special Use Noted 24 Maryland 0
#> 4 2 Female <NA> <NA> 24 Maryland 1
#> 5 2 Female 0 No Special Use Noted 24 Maryland 0
#> STR_VEHNAME ST_CASE TOW_VEH TOW_VEHNAME VEH_NO VE_FORMS
#> 1 Occupant of a Motor Vehicle 240001 0 No Trailing Units 1 1
#> 2 Occupant of a Motor Vehicle 240002 0 No Trailing Units 1 1
#> 3 Occupant of a Motor Vehicle 240003 0 No Trailing Units 1 1
#> 4 01 240005 <NA> <NA> 0 1
#> 5 Occupant of a Motor Vehicle 240005 0 No Trailing Units 1 1
#> WORK_INJ WORK_INJNAME
#> 1 0 No
#> 2 0 No
#> 3 0 No
#> 4 0 No
#> 5 8 Not Applicable (not a fatality)