---
title: "Searchable Codebooks"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Searchable Codebooks}
  %\VignetteEncoding{UTF-8}
  %\VignetteEngine{knitr::rmarkdown}
editor_options: 
  markdown: 
    wrap: 80
---

```{r}
library(rfars)
library(dplyr)
library(stringr)
```

`rfars` comes pre-loaded with searchable codebooks, compiled from SAS format
files and the User Manuals (see: [FARS Analytical User's
Manual](https://crashstats.nhtsa.dot.gov/Api/Public/ViewPublication/813706) and
[CRSS Analytical User's
Manual](https://crashstats.nhtsa.dot.gov/Api/Public/ViewPublication/813707)).
Access the codebooks in RStudio with:

```{r, eval=F, echo=T}
View(rfars::fars_codebook)
View(rfars::gescrss_codebook)
```

It can be helpful to search the codebooks for certain concepts. For example,
below we print out all entries related to speed. This helps find relevant
crashes for analysis and shows how variables change over time.

```{r}
rfars::fars_codebook %>%
  filter(if_any(everything(), ~ str_detect(as.character(.), "speed"))) %>%
  DT::datatable(caption = "Codebook records pertaining to speed")
```
