{"id":16472956,"url":"https://github.com/elipousson/crashapi","last_synced_at":"2025-03-23T11:32:50.255Z","repository":{"id":45124708,"uuid":"421096275","full_name":"elipousson/crashapi","owner":"elipousson","description":"💥🚙💥 R package to get Fatality Analysis Reporting System (FARS) data with the FARS API","archived":false,"fork":false,"pushed_at":"2024-09-06T02:30:00.000Z","size":6671,"stargazers_count":17,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-18T20:07:41.510Z","etag":null,"topics":["r","r-package","rspatial","rstats"],"latest_commit_sha":null,"homepage":"https://elipousson.github.io/crashapi/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elipousson.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":"codemeta.json"}},"created_at":"2021-10-25T16:13:01.000Z","updated_at":"2025-01-07T02:15:00.000Z","dependencies_parsed_at":"2024-10-28T16:09:19.420Z","dependency_job_id":"221cc575-65b8-4be6-9f73-8624e187c5c4","html_url":"https://github.com/elipousson/crashapi","commit_stats":{"total_commits":85,"total_committers":1,"mean_commits":85.0,"dds":0.0,"last_synced_commit":"768429a0096e176a35943a93e7c3260ff2316964"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elipousson%2Fcrashapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elipousson%2Fcrashapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elipousson%2Fcrashapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elipousson%2Fcrashapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elipousson","download_url":"https://codeload.github.com/elipousson/crashapi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245097158,"owners_count":20560311,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["r","r-package","rspatial","rstats"],"created_at":"2024-10-11T12:19:07.532Z","updated_at":"2025-03-23T11:32:49.649Z","avatar_url":"https://github.com/elipousson.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# crashapi\n\n\u003c!-- badges: start --\u003e\n[![CRAN status](https://www.r-pkg.org/badges/version/crashapi)](https://CRAN.R-project.org/package=crashapi)\n[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)\n [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Codecov test coverage](https://codecov.io/gh/elipousson/crashapi/branch/main/graph/badge.svg)](https://app.codecov.io/gh/elipousson/crashapi?branch=main)\n[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)\n\u003c!-- badges: end --\u003e\n\nThe goal of the crashapi R package is to provide functions for downloading data from the National Highway Traffic Safety Administration (NHTSA) [Fatality Analysis Reporting System (FARS) API](https://crashviewer.nhtsa.dot.gov/CrashAPI/).\n\nWhat is FARS? NHTSA explains: \"The Fatality Analysis Reporting System (FARS) contains data on all vehicle crashes in the United States that occur on a public roadway and involve a fatality.\"\n\n## Installation\n\nYou can install the development version of crashapi using the pak package:\n\n``` r\npak::pkg_install(\"elipousson/crashapi\")\n```\n\n## Background\n\n### Fatality Analysis Reporting System (FARS) API support\n\nSupported APIs for this package include:\n\n-   [x] Get Crash List Information\n-   [X] Get Crash Details\n-   [x] Get Crashes By Location\n-   [X] Get Crashes By Vehicle\n-   [x] Get Summary Counts\n-   [x] Get Variables and Get Variable Attributes\n-   [x] Get FARS Data By Year\n-   [X] Get Crashes By Occupant (partial support)\n\nMost of these APIs support XML, JSV, CSV, and JSON output formats. This package only uses JSON with the exception of `get_fars_year()` (which supports downloading CSV files).\n\nFor reference, this package also includes a list of terms and NHTSA technical definitions in `fars_terms` and a list of variable labels in `fars_vars_labels`.\n\nThe FARS API currently provides access to data from 2010 to 2022. The [NHTSA website](https://www-fars.nhtsa.dot.gov/Help/helplinks.aspx) also provides additional information on the release data and version status for the FARS data files available through the API:\n\n| Data Year | File Version | Release Date      |\n|-----------|--------------|-------------------|\n| 2010      | Final        | December 11, 2012 |\n| 2011      | Final        | November 13, 2013 |\n| 2012      | Final        | December 12, 2013 |\n| 2013      | Final        | December 14, 2014 |\n| 2014      | Final        | December 18, 2015 |\n| 2015      | Final        | December 16, 2016 |\n| 2016      | Final        | December 14, 2017 |\n| 2017      | Final        | December 18, 2018 |\n| 2018      | Final        | June 24, 2021     |\n| 2019      | Final        | March 2, 2022     |\n| 2020      | Final        | April 3, 2023     |\n| 2021      | Final        | August 19, 2024   |\n| 2022      | Annual       | August 19, 2024   |\n\n\n### Additional data access functionality\n\nThe `get_fars_zip()` function can be used to access FARS data files from 1975 to 2020 that that are not available via the API but are available for download on through [the NHTSA File Downloads site](https://www.nhtsa.gov/file-downloads?p=nhtsa/downloads/FARS/) as zipped CSV or SAS files (not available through the NHTSA FARS API). This site also provides extensive technical documentation on coding and use of the FARS data files.\n\nEarlier data along with data from the the [General Estimates System](https://www.nhtsa.gov/national-automotive-sampling-system-nass/nass-general-estimates-system) (GES) / [Crash Report Sampling System](https://www.nhtsa.gov/crash-data-systems/crash-report-sampling-system-crss) (CRSS) is also available through the [Fatality and Injury Reporting System Tool](https://cdan.dot.gov/query) (FIRST).\n\n## Examples\n\n```{r}\nlibrary(crashapi)\nlibrary(ggplot2)\n```\n\nMost features for the package can be accessed using the `get_fars()` function that selects the appropriate API-specific function based on the provided parameters. You can also set the API to use with the `api` parameter or use an API-specific function (e.g. `get_fars_summary()`).\n\nFor example, you can use the `get_fars()` access state-level summary data on crash and fatality counts.\n\n```{r get_fars_summary}\n# Get summary crash count and fatality count data for Maryland from 2010 to 2019\nmd_summary \u003c-\n  get_fars(\n    year = c(2010, 2021),\n    state = \"MD\",\n    api = \"summary count\"\n  )\n\nggplot(md_summary, aes(x = CaseYear, y = TotalFatalCounts)) +\n  geom_point(color = \"red\") +\n  geom_line(color = \"red\", group = 1) +\n  theme_minimal()\n```\n\nYou can download crash data and set geometry to TRUE optionally convert the data frame into an `sf` object for mapping.\n\n```{r map_fars_crashes}\ncrashes_sf \u003c-\n  get_fars(\n    year = c(2018, 2021),\n    state = \"NC\",\n    county = \"Wake County\",\n    geometry = TRUE\n  )\n\nnc \u003c- sf::st_read(system.file(\"shape/nc.shp\", package = \"sf\"))\nwake_co \u003c- sf::st_transform(nc[nc$NAME == \"Wake\", ], 4326)\n\n# Map crashes\nggplot() +\n  geom_sf(\n    data = wake_co,\n    fill = NA, color = \"black\"\n  ) +\n  geom_sf(\n    data = sf::st_crop(crashes_sf, wake_co),\n    aes(color = TOTALVEHICLES),\n    alpha = 0.75\n  ) +\n  theme_void()\n```\n\nYou can list crashes and filter by the number of vehicles involved.\n\n```{r get_fars_crash_list}\n# Get fatal crashes in New York state from 2019 with 5 to 10 vehicles\nget_fars(\n  year = 2019,\n  state = \"NY\",\n  vehicles = c(5, 10)\n)\n```\n\nIf you call `get_fars()` or `get_fars_crashes()` with details set to TRUE, additional information from `get_fars_cases()` (including the crash date and time) is appended to the crash data frame.\n\n```{r get_fars_crashes}\n# Get fatal crashes for Anne Arundel County, MD for 2019 and append details\ncrashes_detailed \u003c-\n  get_fars(\n    year = 2019,\n    state = \"MD\",\n    county = \"Anne Arundel County\",\n    details = TRUE\n  )\n\n# Show 10 fatal crashes at random\ndplyr::slice_sample(crashes_detailed, n = 10)\n```\n\n## Related packages and projects\n\n-   [rfars](https://github.com/s87jackson/rfars) aims to \"simplify the process of analyzing FARS data\" by providing access to FARS downloads and preprocessed data back to 2015.\n-   [stats19](https://github.com/ropensci/stats19) \"provides functions for downloading and formatting road crash data\" from \"the UK's official road traffic casualty database, STATS19.\"\n-   [njtr1](https://github.com/gavinrozzi/njtr1): \"An R interface to New Jersey traffic crash data reported on form NJTR-1.\"\n-   [wisdotcrashdatabase](https://github.com/jacciz/wisdotcrashdatabase): \"A package used for internal WisDOT crash database pulls and analysis.\"\n-   [nzcrash](https://github.com/nacnudus/nzcrash): \"An R package to distribute New Zealand crash data in a convenient form.\"\n-   [GraphHopper Open Traffic Collection](https://github.com/graphhopper/open-traffic-collection): \"Collections of URLs pointing to traffic information portals which contain open data or at least data which is free to use.\"\n-   [Open Crash Data Index](https://docs.google.com/spreadsheets/d/1rmn6GbHNkfWLLDEEmA87iuy2yHdh7hBybCTZiQJEY0k/edit?usp=sharing): A Google Sheet listing a range of city, county, regional and state sources for crash data including non-injury crashes as well as the fatal crashes available through the FARS API. Contributions for crash data from other U.S. cities and states are welcome.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felipousson%2Fcrashapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felipousson%2Fcrashapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felipousson%2Fcrashapi/lists"}