---
title: "Introduction to njtr1"
author: "Gavin Rozzi"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
description: >
  This is a short intro to getting started with the njtr1 package
vignette: >
  %\VignetteIndexEntry{Introduction to njtr1}
  %\VignetteEngine{knitr::knitr}
  \usepackage[utf8]{inputenc}
---

```{r setup, include=FALSE}
library(njtr1)
set.seed(1000)
```

`njtr1` is a package that makes it easy to download New Jersey car crash data that is released by the New Jersey Department of Transportation. This package makes it easy to access detailed information on a statewide or county-by-county process that can assist those interested in studying trends in vehicle crashes in New Jersey.

## Usage

The main function of this package is `get_njtr1()`. This function allows you to specify the specific table of NJTR-1 data that you'd like to query for a given year.

There are 5 different tables available with NJTR-1 data and published by the NJDOT. We will take a look at each of them in the following examples.

### Accidents

```{r, eval = FALSE}
get_njtr1(year = 2019, type = "Accidents")
```

### Drivers

```{r, eval = FALSE}
get_njtr1(year = 2019, type = "Drivers")
```

### Vehicles

```{r, eval = FALSE}
get_njtr1(year = 2019, type = "Vehicles")
```

#### Insurance company data

Each of the vehicle records contain a field name `insurance_company_code` that identifies the name of the insurance company that covers the vehicle involved in an accident.

This code can be used to join the vehicle data with a dataset containing details for every insurance company that does business in New Jersey.

Access the insurance from the package like so:
```{r}
data("insurance")
head(insurance)
```

The insurance dataset contains a field `ID_NO` which is the same as `insurance_company_code` in the Vehicles table. This common field can be used for performing join operations. 

### Pedestrians

```{r, eval = FALSE}
get_njtr1(year = 2019, type = "Pedestrians")
```

### Occupants

```{r, eval = FALSE}
get_njtr1(year = 2019, type = "Occupants")
```
