Title: | Tools for Traffic Accident Data in Japan |
---|---|
Description: | What the package does (one paragraph). |
Authors: | Keisuke ANDO [aut, cre] |
Maintainer: | Keisuke ANDO <[email protected]> |
License: | CC BY 4.0 |
Version: | 0.1.3 |
Built: | 2024-11-12 06:27:47 UTC |
Source: | https://github.com/NONONOexe/jpaccidents |
This function converts DMS (degree-minute-second) to decimal degrees. The input DMS values must be in the format of "DDDMMSSsss" where:
D: Degrees (1–3 digits)
M: Minutes (2 digits)
S: Seconds (2 digits)
s: Milliseconds (3 digits)
convert_deg(dms)
convert_deg(dms)
dms |
A numeric vector of DMS values in the format of "DDDMMSSsss" |
A numeric vector of decimal degrees.
convert_deg(c("431007628", "1410328320")) convert_deg(c(431007628, 1410328320))
convert_deg(c("431007628", "1410328320")) convert_deg(c(431007628, 1410328320))
Download the file of traffic accident data provided the National Police Agency's Web page.
download_accident_data(type, download_dir = getwd(), year = 2023)
download_accident_data(type, download_dir = getwd(), year = 2023)
type |
Type of data to download: one of "main", "sub", or "highway". |
download_dir |
A directory where downloaded file is to saved
(default: |
year |
Year the traffic accident data was recorded.
Available from 2019 to 2023 (default: |
The traffic accident data are divided into the following types:
"main" (honhyo): Basic data on traffic accidents.
"sub" (hojuhyo): Additional data related to the "main" data.
"highway" (kosokuhyo): Data on traffic accidents on highways.
You can specify the type of data directly via the type
argument.
Path of the downloaded file (invisibly).
## Not run: download_accident_data("main", "download-dir-path", 2023) download_accident_data("sub", "download-dir-path", 2023) download_accident_data("highway", "download-dir-path", 2023) ## End(Not run)
## Not run: download_accident_data("main", "download-dir-path", 2023) download_accident_data("sub", "download-dir-path", 2023) download_accident_data("highway", "download-dir-path", 2023) ## End(Not run)
This function filters data by a specific tag.
filter_data_by_tag(data, tag)
filter_data_by_tag(data, tag)
data |
An accident data object. |
tag |
A character string specifying the tag to filter by. |
A data frame containing only the columns with the specified tag.
## Not run: person_data <- filter_data_by_tag(accident_data, "person") ## End(Not run)
## Not run: person_data <- filter_data_by_tag(accident_data, "person") ## End(Not run)
This function retrieves the configuration that were loaded using
load_config()
.
get_config()
get_config()
A list containing the configuration.
load_config()
for loading the configuration.
reset_config()
for resetting the configuration.
get_config()
get_config()
This function loads the accident data configuration from a YAML file.
load_config(config_path)
load_config(config_path)
config_path |
Path to the YAML file containing the configuration. |
get_config()
for retrieving the configuration.
reset_config()
for resetting the configuration.
to the default values.
## Not run: load_config("path/to/config.yaml") ## End(Not run)
## Not run: load_config("path/to/config.yaml") ## End(Not run)
This function retreieves the new column names corresponding to
the original column names in a specified dataset. The column
names are based on the configuration loaded by load_config()
.
This is useful when the original names are in Japanese (2-byte
characters), which can be difficult to handle in programs.
This function converts them to corresponding English names.
lookup_column_names(dataset_name, original_names)
lookup_column_names(dataset_name, original_names)
dataset_name |
The name of the dataset. |
original_names |
A vector of original column names. |
A vector of new column names corresponding to the provided original names.
lookup_column_names("main_data", c("死者数", "天候"))
lookup_column_names("main_data", c("死者数", "天候"))
This function determines the dataset name based on the file path and configuration.
lookup_dataset_name(file)
lookup_dataset_name(file)
file |
A character string specifying the file path. |
Dataset name
lookup_dataset_name("example/honhyo_2023.csv")
lookup_dataset_name("example/honhyo_2023.csv")
These function perform post-processing operations on different datasets.
post_process_main
processes the main data (honhyo), separating it into
accident and person data, and returning them as a list.
post_process_sub
and post_process_highway
currently do not perform
any modifications on sub data and highway data, respectively.
post_process_main(data) post_process_sub(data) post_process_highway(data)
post_process_main(data) post_process_sub(data) post_process_highway(data)
data |
The data to be processed. |
A processed data.
This function reads accident data from a CSV file, renames the columns, adds attributes and class, and applies post-processing if provided.
read_accident_data( file, post_process = select_post_processor(lookup_dataset_name(file)) )
read_accident_data( file, post_process = select_post_processor(lookup_dataset_name(file)) )
file |
The path to the CSV file. |
post_process |
A function to apply post-processing to the data. |
A data frame containing the accident data.
## Not run: read_accident_data("example/honhyo_2023.csv") ## End(Not run)
## Not run: read_accident_data("example/honhyo_2023.csv") ## End(Not run)
This function resets the configuration to the default values.
reset_config()
reset_config()
get_config()
for retrieving the configuration.
load_config()
for loading the configuration.
reset_config()
reset_config()
This function selects the post-processor function based on the given dataset name.
select_post_processor(dataset_name)
select_post_processor(dataset_name)
dataset_name |
The name of the dataset. |
The post-processing function corresponding to the dataset name.