knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
This is an example R package built 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.
You can install from github:
#> devtools::install_github([path to this repository])
To load package once installed:
library(examplepackage)
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.