import_db_data: Import crash, vehicle, person from crash database

View source: R/database_imports.R

import_db_dataR Documentation

Import crash, vehicle, person from crash database

Description

This imports all data based on crash db type, years selected, and columns selected. It combines old and new crash data into a single dataframe. It renames columns of the old db to match db and renames some variables, such as CRSHSVR, to match new db. Note: if an old db is imported, all columns will be imported.

Usage

import_db_data(
  db_loc = "C:/data/crashes_duck.duckdb",
  db_type = "crash",
  years = c("21"),
  columns = c("CRSHSVR"),
  filter_by = NULL
)

Arguments

db_loc

location of crash database file ("C:/data/crashes_duck.duckdb")

db_type

Type of database - any one of "crash", "vehicle", or "person"

years

Year(s) of db data c("20", "21").

columns

Columns to be imported. For the new db these columns will always be imported (if applicable): "CRSHNMBR", "CRSHDATE", "CNTYCODE ,"CRSHSVR", "UNITNMBR", "ROLE","VEHTYPE","WISINJ", "UNITPRSN", "UNITTYPE". Columns with multiples, like DRVRPC and ANMLTY, only the first part without the number should be inputted. For old db, all columns will be imported. If columns = "all", all columns will be selected.

filter_by

Option to filter by county, separated by a comma. Use "county:Dane, Rock"

Details

Note that DRVRFLAG is derived differently for old and new db. New db defines a driver of any MV, while old db also include non-motorists.

Value

df of either crash, vehicle or person. 'year' column.

Examples

import_db_data(db_loc = "C:/data/crashes_duck.duckdb", db_type = "crash",
  years = c("16", "17","18"), columns = c("DRVRPC"))

jacciz/wisdotcrashdatabase documentation built on June 3, 2023, 2:26 a.m.