Changelog
Source:NEWS.md
crashapi (development version)
- New
fars_value_labels()returns value labels (the decoded value for each code) for FARS (1975-2024) and CRSS (2016-2024) variables by year, built from the SAS format files NHTSA publishes with each year of data. Newdecode_fars()uses these labels to decode FARS or CRSS data withdecode = "names"(add…NAMEcolumns),decode = "replace"(replace codes with factors of decoded values for categorical variables), ordecode = "labelled"(add value labels withhaven::labelled()).get_fars()gains the samedecodeargument (with an additional"none"option) and adds…NAMEcolumns by default where they are missing (FARS data before 2015) (#4). - New
fars_variables()returns year-specific variable labels for FARS and CRSS variables from the SAS data files NHTSA publishes with each year of data. Variable labels from these files are now used (beforefars_vars_labels) when the table and year are known, which labels variables added in recent years, discontinued variables, and CRSS-only variables (e.g.WEIGHT). -
fars_vars_labelsadds title case labels for columns only returned by the CrashAPI (e.g. nested list columns fromget_fars_cases(),STATEINITIAL, and vPIC variables in the VINDERIVED table), so every column returned by the CrashAPI now has a variable label. Variable labels from the SAS data files are used for variables that were only added in later years. -
get_fars_zip()andget_crss_zip()now retry failed downloads, give a clearer error when a file isn’t available, and no longer leave a partially downloaded zip file in the cache if a download fails. - Breaking change:
get_fars()is redesigned to return a FARS data table (e.g. accident, person, or vehicle) for one or more states, an optional county, and one or more years, similar tostats19::get_stats19(). Data for a state from 2010 onwards comes from the CrashAPI and national data, Puerto Rico, or data before 2010 comes from zipped data files (setsourceto choose). Tables are filtered by county directly or by matching crashes in the county from the accident table. Theapi,cases,vehicles,details,format,pr,path, anddownloadarguments are removed; useget_fars_crashes(),get_fars_cases(),get_fars_crash_list(),get_fars_summary(), orget_fars_year()for other CrashAPI endpoints. - Breaking change:
get_fars_zip()andget_crss_zip()now convert zipped CSV files to parquet files cached in the user cache directory (orgetOption("crashapi.cache_dir")) and remove the zip and CSV files unlesskeep_files = TRUE. Later calls read the cached files without downloading the data again unlessoverwrite = TRUE. Withread = FALSE, they return the parquet file paths named by table (or a list named by year for multiple years). crashapi now imports nanoparquet. - crashapi now requires R 4.1.0 or later, matching its dependencies and its use of the native pipe.
- Fix package to use the current CrashAPI base URL and browser headers (broken since January 2025).
- Breaking change: required arguments now come before
yearinget_fars_crashes()(state,county),get_fars_cases()(state,cases),get_fars_crash_list(),get_fars_summary(),get_fars_year(),get_fars_crash_vehicles()(state,make,model,model_year,body_type), andget_fars_crash_persons()(state,age,sex,seat,injury). Calls that passyearby position need to name it. -
get_fars_crash_persons()now works.age,sex,seat, andinjuryare all required since the CrashAPI returns an error unless all four are provided (contrary to NHTSA’s documentation), and names (e.g.sex = "female",seat = "front left",injury = "fatal") are converted to codes. Theoccupantsandnonoccupantsarguments are removed since the seat position determines whether occupants or non-occupants are returned. -
get_fars_crash_vehicles()now requiresmake,model,model_year, andbody_typesince the CrashAPI returns an error unless all four are provided, and accepts names or numeric IDs formake,model, andbody_type(previously only character IDs worked). - Data from 2024 (released in April 2026) is now supported and the default
yearfor all functions isgetOption("crashapi.year", 2024). Useoptions(crashapi.year = 2022)to set a different default year for the session. - Breaking change: the
start_yearandend_yeararguments are removed. Functions for API endpoints that take a range of years (get_fars_crashes(),get_fars_crash_list(),get_fars_summary(),get_fars_year(),get_fars_crash_vehicles(), andget_fars_crash_persons()) now use the minimum and maximum ofyearas the start and end year, with a message ifyearhas gaps. -
fars_vars()supports multiple years and returns ayearcolumn. -
get_fars_crashes()errors with a clear message ifcountyis missing. -
get_fars()andget_fars_crashes()now error ifcountycan’t be matched to a county instate(e.g. an ambiguous name like “Baltimore” or an invalid FIPS code) instead of filtering by the state FIPS code and returning no rows. - Matching state and county names now returns FIPS codes for valid values when some values are invalid and drops county names that match more than one county (e.g. “Baltimore”) with a warning asking for a more specific name.
-
get_fars_cases(details = "events")andget_fars_cases(details = "vehicles")now return details for all cases instead of only the first case, andget_fars_cases()errors clearly if no case details are found. -
get_fars_zip()andget_crss_zip()now error before downloading ifread = TRUEandformat = "sas". -
read_crashapi()no longer errors for responses without results and returnsNULLwith the CrashAPI message. -
get_fars_cases()supports one year for each case number, andget_fars_crashes(details = TRUE)now works for multiple years by using the case year for each crash. -
get_fars_zip()andget_crss_zip()now read CSV files from the folder inside newer zip files, which previously causedread = TRUEto fail for most recent years. -
get_crss_zip(year = 2019, aux = TRUE)now handles the misspelled file name on the NHTSA site, andget_crss_zip()is documented with a description of CRSS and a link to the official CRSS page. -
get_fars_zip()andget_crss_zip()warn ifgeometry = TRUEand the accident table has no coordinate columns (e.g. CRSS data or older FARS data) instead of silently returning a data frame. -
get_fars_zip(pr = TRUE)now uses the correct file name for Puerto Rico data and errors for years without Puerto Rico data (1975-1977 and 1979).get_fars_zip(year = 1996, aux = TRUE)now handles the misspelled file name on the NHTSA site. -
get_fars_zip()andget_crss_zip()support multiple years and return a list named by year. -
format_crashes(),get_crss_zip(),get_fars(),get_fars_cases(),get_fars_crash_list(),get_fars_crash_persons(),get_fars_crash_vehicles(),get_fars_crashes(),get_fars_summary(),get_fars_year(), andget_fars_zip()gain avar_labelsargument. When"attribute"(the default), each column with a matching variable infars_vars_labelsgets a"label"attribute (use"none"to skip variable labels), which is shown byView()and used by packages such as gt and gtsummary. Where a variable appears in more than one FARS data file, the label for the table being read is used. - Variable labels now prefer labels for current variables over discontinued ones, match names case-insensitively when there is no exact match (e.g.
CASEYEAR), label…NAMEcolumns from their coded variable (e.g.BODY_TYPNAMEfromBODY_TYP), and label nested data frames in list columns returned byget_fars_cases(). -
format_crashes()now reorders columns, converts coordinate and count columns, and appendsdate,time, anddatetimecolumns as documented. Previously, a faulty check skipped this step, soget_fars_crashes(),get_fars_crash_list(), andget_fars_summary()returned unformatted data. Column names are kept as returned by the API, and columns not found infars_vars_labelsare kept at the end. -
get_fars_year()now supports the “RACE” (2019 onwards) and “TRAILERVINDERIVED” (2016 onwards) tables. -
get_fars_year()now sends the same browser headers as other API requests when reading CSV data or downloading a file (download = TRUE), and returns the downloaded file path invisibly. -
get_fars_year()returns the data with a warning whengeometry = TRUEand the table has no coordinate columns, instead of downloading a file.
crashapi 0.1.1.9
- Update year range to cover 2021 data.
- Add
get_crss_zip()function
crashapi 0.1.1
CrashAPI now has data from 2010 to 2020. get_fars_year() is also updated to support multiple years and to include a state parameter which makes it much easier to use.
- refactor: update 2019 -> 2020 max year
- feat: add geometry and state parameter support to
get_fars_year() - refactor: set default crs to NULL and switch to use
sfext::df_to_sf - refactor: switch to use
httr2package +read_crashapi()for data access (except for zip) - test: add tests and set up code coverage tests
crashapi 0.1.0.12
- feat: Add
get_fars_crash_persons()function - refactor: Rename
tidy_crashes()toformat_crashes() - feat: rename
get_fars_crash_details()toget_fars_cases() - feat: Add details parameter to
get_fars_crashes()to supported appending detailed case information - feat: Add
fars_vars_labelswith names and labels derived from current analytical manual
crashapi 0.1.0.11
- feat: add
get_fars()function that uses an api parameter to call different APIs - feat: import helper functions from {tigris} package to improve renamed
lookup_fips()function - feat: Add
get_fars_crash_vehiclesto support downloading crash data by vehicle make, model, and/or body type - fix:
get_fars_yearwas not using the correct query URL if download = TRUE - refactor: relocate helper functions to utils.R
- refactor: rename
make_query()helper function toread_api() - refactor: update
validate_year()helper function to work with {checkmate} package - refactor: update default values for year, start_year, end_year and other parameters
- docs: Update README and pkgdown site
crashapi 0.1.0.10
- feat:
get_fars_zipadded to provide alternate (non-API) method for downloading zipped CSV or SAS data files - fix:
get_fars_crash_detailsupdated to return data frame w/o list columns - feat:
get_fars_crash_detailsupdated to optionally return vehicle or crash events data frames
crashapi 0.1.0.9
- docs: Revise README and update pkgdown site
- fix: Add missing imports to
DESCRIPTION - fix: Update
county_to_fips()to support partial county names, e.g. “Adams” instead of “Adams County” and avoiding matching multiple counties (closes #1) - feat: Update
get_fars_crash_details()to return sf objects using geometry parameter - refactor: Set up API calls w/ unexported utility function (
make_query)
crashapi 0.1.0
- Added functions for accessing FARS APIs including Get Crash List Information, Get Crash Details, Get Crashes By Location, Get Summary Counts, and Get FARS Data By Year (documented in
get_fars()) - Added functions for accessing FARS APIs including Get Variables and Get Variable Attributes (documented in
get_fars_vars()) - Added
fars_termsdata with terms and definitions from National Highway Traffic Safety Administration (NHTSA) website - Added a
NEWS.mdfile to track changes to the package. - Set up a pkgdown website