knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 5, fig.height = 5, fig.align = "center")
library(fars)

Welcome!

This vignette gives a high-level description of the sample data, the available functions and how they interact.

Sample data

The raw data in the inst/extdata directory covers the years 2013 to 2015. There is one file per year, in csv.bz2 format.

The package uses the following subset of variables:

Variable | Description ---------------|----------------------------------------------------------- year | Integer representing a year e.g. 2013. (Taken from the filename not from within the file). MONTH | Integer 1 to 12 representing a month Jan to Dec. STATE | Integer representing a FIPS 2-character state numeric code (e.g. 48 is Texas). LONGITUD | Numeric value of longitude. (Values > 900 are treated as outliers when plotting). LATITUDE | Numeric value of latitude. (Values > 90 are treated as outliers when plotting).

Functions

Five functions are available; all exported for the user:

Function | Description -------------------------|------------------------------------------- make_filename() | Generate FARS filename for a given year fars_read() | Read a FARS csv file into a tibble fars_read_years() | Read FARS data for a vector of years (helper function used by fars_summarize_years) fars_summarize_years() | Summarise FARS observation counts by year and month fars_map_state() | Draw a geographical map of accident sites for a specific US state and year

The low level function help accessed via ? covers parameters, outputs, examples, dependent functions and errors.

Frequent tasks

Using internal (sample) and external data

For all functions except fars_read() I have added a Boolean parameter internal which specifies to use either the package sample data (value TRUE, the default), or external data (value FALSE).

Summary: if you just want to use sample data, you can invoke all the functions without setting this parameter.

Examples

#1: Generate raw data filenames for year 2013 (internal and external).

For internal files, the filepath is specific to your installation and OS.

For external files, no folder path is included. If passed to file_read(), R will use your current working directory.

make_filename(2013) # Default is internal=TRUE so uses sample data
make_filename(2013, internal=FALSE) # External data.

#2: Display head of the 2013 sample data.

head(fars_read(make_filename(2013)))

#3: Count the number of sample data years.

length(fars_read_years(2013:2015))

#4: Count sample data rows for years 2013 to 2015.

fars_summarize_years(2013:2015)

#5: Plot sample data: State 48 (Texas) for 2015.

fars_map_state(48,2015)


rwpalin/fars documentation built on Nov. 5, 2019, 5:10 a.m.