knitr::opts_chunk$set(echo = TRUE)

This vignette serves to illustrate how to use the farsfunctions package. The farsfunctions package, contains geodata for car accidents for each state in the US for the years 2013-2015.

Load packages

library(dplyr, quietly = T)
library(tidyr, quietly = T)
library(farsfunctions, quietly = T)

fars_map_state() is the main function of the package, and it visualizes accidents The function takes two arguments, state number and year.

fars_map_state(state.num = 44, year = 2013)

devtools::document()
setwd(system.file("inst/extdata/", package = "farsfunctions"))
fars_map_state(state.num = 44, year = 2013)

Another useful function in the package is fars_summarize_years, which given a list of years, generates a summary table of the accidents for each month for the given years.

fars_summarize_years(c(2014,2015))

setwd(system.file("./inst/extdata/", package = "farsfunctions"))
fars_summarize_years(c(2013,2014))

In addition to the main functions, a couple of helper functions are also included in the package. fars_read_years also takes a list of years and returns data for the given years (Not shown)

fars_read_years(c(2013,2014))

setwd(system.file("./inst/extdata/", package = "farsfunctions"))
fars_read_years(c(2013,2014))

Two other small functions are make_filename which takes a year as input, and returns the corresponding filename+incl. path, and fars_read, which given a filename reads the coresponding data into memory.

make_filename(2013)

fars_read()

setwd(system.file("inst/extdata/", package = "farsfunctions"))
make_filename(2013)
fars_read("accident_2013.csv.bz2")


JLYJabc/farsfunctions documentation built on May 28, 2019, 7:51 a.m.