knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Introduction

This is an example package for Coursera's Mastering Software Development in R course 2: Building an R Package.

This Package loads, summarizes and plots US National Highway Traffic Safety Administration's Fatality Analysis Reporting System (source), with yearly data on fatal injuries suffered in motor vehicle traffic crashes.

Installation

library(examplepackage)

The package includes raw datasets for the years 2013, 2014, and 2015. To access the datasets use:

# to access raw data included with the packange:
#> system.file('extdata', 'accident_2013.csv.bz2', package='examplepackage')

Usage

The package provides utility functions to: access the data in a data frame summarize accidents by year * plot the data by state against a map of the US using the maps package. Note that if datadir argument is not provided, built-in data is loaded automatically.

To access raw data in a data frame:

df = fars_read(filename = 'accident_2013.csv.bz2',   # filename of the built-in dataset for 2013
               datadir = NULL)                       # this loads from the built-in datasets
head(df)

To summarize the data:

fars_summarize_years(c(2013, 2014))

To plot the location of fatalities for state indexed 1 for year 2013:

fars_map_state(1, 2013)


kamenbliznashki/examplepackage documentation built on Dec. 9, 2019, 12:16 a.m.