Title: | Tools for Traffic Accident Data in Japan |
---|---|
Description: | In Japan, traffic accident data are published by the National Police Agency. This package provides tools to efficiently handle and standardise these datasets, facilitating seamless analysis and integration into various workflows. By using this package, users can uncover patterns in traffic accidents and identify high-risk scenarios, supporting efforts to enhance road safety and prevent future incidents. |
Authors: | Keisuke Ando [aut, cre] |
Maintainer: | Keisuke Ando <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.4 |
Built: | 2025-02-09 02:52:12 UTC |
Source: | https://github.com/NONONOexe/jpaccidents |
download_accident_data()
downloads the file of traffic accident data
provided the National Police Agency.
download_accident_data(type, download_dir = getwd(), years = 2023)
download_accident_data(type, download_dir = getwd(), years = 2023)
type |
A character string specifying the type of data to download: one of "main", "supp", or "highway". |
download_dir |
A character string specifying the directory to save the
downloaded files (default: |
years |
An integer or vector of integers specifying the years of the
data to download. Available years are 2019 to 2023 (default: |
The traffic accident data are divided into the following types:
"main"
: Basic data on traffic accidents (honhyo).
"supp"
: Additional data related to the "main"
data (hojuhyo).
"highway"
: Data on traffic accidents on highways (kosokuhyo).
Use the type
argument to specify which data type to download.
A character vector of file paths for the downloaded files (invisibly).
## Not run: # Download the main data for 2023 download_accident_data("main", "download-dir-path", 2023) # Download the supplementary data for 2023 download_accident_data("supp", "download-dir-path", 2023) # Download the highway data for 2019 to 2023 download_accident_data("highway", "download-dir-path", 2019:2023) ## End(Not run)
## Not run: # Download the main data for 2023 download_accident_data("main", "download-dir-path", 2023) # Download the supplementary data for 2023 download_accident_data("supp", "download-dir-path", 2023) # Download the highway data for 2019 to 2023 download_accident_data("highway", "download-dir-path", 2019:2023) ## End(Not run)
These functions filter accident data based on the specified categories.
filter_accident_type(data, accident_type) filter_road_shape(data, road_shape)
filter_accident_type(data, accident_type) filter_road_shape(data, road_shape)
data |
A |
accident_type |
A vector of specifying the accident type to filter. Must be one of the following values:
|
road_shape |
A vector of specifying the road type to filter. Must be one of the following values:
|
A filtered accident_data
object.
## Not run: # Extract accidents where vehicle collided with pedestrian vehicle_to_pedestrian_collisions <- data %>% filter_accident_type("vehicle_to_pedestrian") # Extract accidents involving vehicle-to-vehicle collisions vehicle_to_pedestrian_collisions <- data %>% filter_accident_type("vehicle_to_pedestrian") # Extract accidents that occured on curved roads curved_road_accidents <- data %>% filter_road_shape("curve") ## End(Not run)
## Not run: # Extract accidents where vehicle collided with pedestrian vehicle_to_pedestrian_collisions <- data %>% filter_accident_type("vehicle_to_pedestrian") # Extract accidents involving vehicle-to-vehicle collisions vehicle_to_pedestrian_collisions <- data %>% filter_accident_type("vehicle_to_pedestrian") # Extract accidents that occured on curved roads curved_road_accidents <- data %>% filter_road_shape("curve") ## End(Not run)
filter_collision_pattern()
filters accident data based on primary and
secondary impact conditions for each party involved in the accident.
filter_collision_pattern( data, primary_impacts, secondary_impacts = NA_character_ )
filter_collision_pattern( data, primary_impacts, secondary_impacts = NA_character_ )
data |
A list containing accident data. |
primary_impacts |
A vector specifying the initial collision points (primary impact) for each involved party. |
secondary_impacts |
A vector specifying the subsequent collision points
(secondary impact) for each involved party (default: |
The values of primary_impacts
and secondary_impacts
are following:
"no_impact"
: No impact
"front"
: Front of the vehicle
"right"
: Right side of the vehicle
"rear"
: Rear of the vehicle
"left"
: Left side of the vehicle
"front_right"
: Front right of the vehicle
"rear_right"
: Rear right of the vehicle
"rear_left"
: Rear left of the vehicle
"front_left"
: Front left of the vehicle
The order of values in primary_impacts
and secondary_impacts
corresponds to the party order (party_order
).
A list containing filtered accident data.
## Not run: # Filter accident data by cases indicating head-on collisions head_on_collisions <- filter_collision_pattern(data, c("front", "front")) # Filter accident data by cases indicating rear-end collisions rear_end_collisions <- filter_collision_pattern(data, c("rear", "front")) ## End(Not run)
## Not run: # Filter accident data by cases indicating head-on collisions head_on_collisions <- filter_collision_pattern(data, c("front", "front")) # Filter accident data by cases indicating rear-end collisions rear_end_collisions <- filter_collision_pattern(data, c("rear", "front")) ## End(Not run)
merge_accident_data()
merges multiple accident_data
objects into a
single accident_data
object.
merge_accident_data(...) ## S3 method for class 'accident_data' merge_accident_data(...) ## S3 method for class 'list' merge_accident_data(data_list, ...)
merge_accident_data(...) ## S3 method for class 'accident_data' merge_accident_data(...) ## S3 method for class 'list' merge_accident_data(data_list, ...)
... |
|
data_list |
A list of |
A merged accident_data
object.
read_accident_data()
reads accident data from multiple CSV files,
processes each file, and combines the data into three categories:
accident_info
: Basic accident information including date, location,
and conditions
person_info
: Information about individuals involved in the accidents
highway_info
: Information specific to accidents that occurred on
highways/expressways
read_accident_data(file_paths)
read_accident_data(file_paths)
file_paths |
A character vector of file paths to the CSV files. |
A list containing three data frames (accident_info
, person_info
,
and highway_info
).
## Not run: # Read main and supplementary data for 2023 read_accident_data(c("example/honhyo_2023.csv", "example/hojuhyo_2023.csv")) ## End(Not run)
## Not run: # Read main and supplementary data for 2023 read_accident_data(c("example/honhyo_2023.csv", "example/hojuhyo_2023.csv")) ## End(Not run)