knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(CourseraBuildingRPckg)
library(dplyr)
library(maps)

CourseraBuildingRPckg is a peer reviewed project to practice R package Building

This packages provides functions to process and plot data from the US National Highway Traffic Safety Administration's Fatality Analysis Reporting System.

Those functions require that current working directory contains FARS data from the given year named like accident_[year].csv.bz2

The data

The packages has 3 files relating the FARS data from 2013 to 2015.

They are accessible under the folder accessible by running the following line.

system.file("extdata", package = "CourseraBuildingRPckg")

Those files can also be used by setting current directory as following right before calling the function (in the same chunk):

setwd(system.file("extdata", package = "CourseraBuildingRPckg"))

Summarizing data

Let's process the accidents data of 2013 by summarizing them by month in year in a tibble using the fars_summarize_years() function.

setwd(system.file("extdata", package = "CourseraBuildingRPckg"))
#Needed if you want to use data from the package, otherwise function will look for files in the directory the function is run.
#getwd()
fars_2013 <- fars_summarize_years(2013)
fars_2013

Nota Bene fars_summarize_years() can also create a summary report for multiple years.

setwd(system.file("extdata", package = "CourseraBuildingRPckg"))
fars_2013_2014 <- fars_summarize_years(c(2013, 2014))
fars_2013_2014

Visualizing data

The fars_map_state function will plot all accidents locations for a given year and federal state on a US federal state map.

setwd(system.file("extdata", package = "CourseraBuildingRPckg"))
fars_map_state(26, 2014)


Capucine0210/CourseraProject documentation built on Jan. 1, 2022, 3:06 p.m.