knitr::opts_chunk$set(
  eval = TRUE,
  collapse = TRUE
)

#Changing teh working directory for running the code
knitr::opts_knit$set(
  root.dir = system.file("extdata", package = "farsr")
  )

Overview

The goal of fars package is to help you performing basic operation on Fatality Analysis Reporting System (FARS) data, a nationwide census providing the American public yearly data regarding fatal injuries suffered in motor vehicle traffic crashes. Specifically it allows you to perform the following operations:

The following functions are made available through the package:

| Function | | | :--------- | :-------------- | | fars_read() | Read a FARS datafile | | fars_read_years() | Read FARS datafile(s) for provided year(s) | | fars_summarize_years() | Summarizes injuries by month for provided year(s) | |fars_map_state() | Visualize map with injuries for provided state (USA) and year |

How to install the package

The installation of the fars package is done using its github repository and the install_github() function in the devtools package.

#Using devtools and Github
#Setting up the flag to build the vignette of the package
devtools::install_github("pparacch/fars", build_vignettes = TRUE)

Getting Started

Load and attach the package

library(farsr)

How to read a FARS datafile into memory

Using fars_read is possible for the user to load a specific file into memory. The file must be a FARS datafile. The unique location of the FARS datafile must be provided as argument using a relative or an absolute path.

fars_datafile_path <- system.file("extdata", "accident_2013.csv.bz2", package = "farsr") 
fars_data <- fars_read(fars_datafile_path)
head(fars_data)

How to create a filename compliant with FARS format

Using make_filename is possible for the user to generate a filename compliant with the FARS format. The year associated to the FARS data must be provided as argument (e.g. integer or character).

year_fars_data <- 2017 #or "2017"
make_filename(year = year_fars_data)

How to get FARS data for selected years limited to MONTH

Using fars_read_years is possible for the user to load in memory the FARS data limited to the MONTH feature for the provided years. The years of interest must be provided as argument using a vector of integer or character. If there is no FARS data for a selected year then NULL is returned for that year.

The working directory must contains the required FARS datafile for the years of interest.

years_fars_data <- c(2013, 2014) # or c("2013", "2014")
fars_read_years(years = years_fars_data)

How to summarize the number of fatal accidents by year

Using fars_summarize_years is possible for the user to load in memory the summary of the fatal accidents extrapolated from the FARS data for the provided years. The years of interest must be provided as argument using a vector of integer or character.

years_fars_data <- c(2013, 2014) # or c("2013", "2014")
fars_summarize_years(years = years_fars_data)

Visualize the map of fatal accidents for a specific year and state (USA)

Using fars_map_state is possible for the user to visualize the map of fatal accidents for a specific year and state.

year_fars_data <- 2013 # or "2013"
state.num <- 1
fars_map_state(state.num = state.num, year = year_fars_data)


pparacch/fars documentation built on May 6, 2019, 6:01 p.m.