Package 'jpaccidents'

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

Help Index


Convert DMS (degree-minute-second) to decimal degrees

Description

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)

Usage

convert_deg(dms)

Arguments

dms

A numeric vector of DMS values in the format of "DDDMMSSsss"

Value

A numeric vector of decimal degrees.

Examples

convert_deg(c("431007628", "1410328320"))
convert_deg(c(431007628, 1410328320))

Download the traffic accident data

Description

Download the file of traffic accident data provided the National Police Agency's Web page.

Usage

download_accident_data(type, download_dir = getwd(), year = 2023)

Arguments

type

Type of data to download: one of "main", "sub", or "highway".

download_dir

A directory where downloaded file is to saved (default: getwd()).

year

Year the traffic accident data was recorded. Available from 2019 to 2023 (default: 2023).

Details

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.

Value

Path of the downloaded file (invisibly).

Examples

## 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)

Filter data by tag

Description

This function filters data by a specific tag.

Usage

filter_data_by_tag(data, tag)

Arguments

data

An accident data object.

tag

A character string specifying the tag to filter by.

Value

A data frame containing only the columns with the specified tag.

Examples

## Not run: 
person_data <- filter_data_by_tag(accident_data, "person")

## End(Not run)

Get configuration

Description

This function retrieves the configuration that were loaded using load_config().

Usage

get_config()

Value

A list containing the configuration.

See Also

load_config() for loading the configuration.

reset_config() for resetting the configuration.

Examples

get_config()

Load configuration from YAML file

Description

This function loads the accident data configuration from a YAML file.

Usage

load_config(config_path)

Arguments

config_path

Path to the YAML file containing the configuration.

See Also

get_config() for retrieving the configuration.

reset_config() for resetting the configuration. to the default values.

Examples

## Not run: 
load_config("path/to/config.yaml")

## End(Not run)

Lookup new column names for an accident dataset

Description

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.

Usage

lookup_column_names(dataset_name, original_names)

Arguments

dataset_name

The name of the dataset.

original_names

A vector of original column names.

Value

A vector of new column names corresponding to the provided original names.

Examples

lookup_column_names("main_data", c("死者数", "天候"))

Find dataset name from file path

Description

This function determines the dataset name based on the file path and configuration.

Usage

lookup_dataset_name(file)

Arguments

file

A character string specifying the file path.

Value

Dataset name

Examples

lookup_dataset_name("example/honhyo_2023.csv")

Post-process data

Description

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.

Usage

post_process_main(data)

post_process_sub(data)

post_process_highway(data)

Arguments

data

The data to be processed.

Value

A processed data.


Read accident data from a CSV file

Description

This function reads accident data from a CSV file, renames the columns, adds attributes and class, and applies post-processing if provided.

Usage

read_accident_data(
  file,
  post_process = select_post_processor(lookup_dataset_name(file))
)

Arguments

file

The path to the CSV file.

post_process

A function to apply post-processing to the data.

Value

A data frame containing the accident data.

Examples

## Not run: 
read_accident_data("example/honhyo_2023.csv")

## End(Not run)

Reset Configuration

Description

This function resets the configuration to the default values.

Usage

reset_config()

See Also

get_config() for retrieving the configuration.

load_config() for loading the configuration.

Examples

reset_config()

Select post-processor function based on dataset name

Description

This function selects the post-processor function based on the given dataset name.

Usage

select_post_processor(dataset_name)

Arguments

dataset_name

The name of the dataset.

Value

The post-processing function corresponding to the dataset name.