The fars package is meant to provide an interface to access accident data for different US-States from locally saved csv-files for each year and to enable the user to quickly generate both monthly summmaries of the data as well as visualize accident locations on state maps.
The package contains the following functions:
fars_read
make_filename
fars_read_years
fars_summarize_years
fars_map_state
In the following only functions 3 to 5 are explained since they are the only ones meant to be called by the user directly. However help documentation for all functions can be retrieved any time using the R help function ?
and the function name.
fars_read_years
This function takes in a vector or list of years as integers, reads in the data for all those years and returns it as a list of data frames. It assumes that the data for all years sits in your current working directory in the format specified above. It will skip years for which this is not the case with a warning.
This function is used in the following way:
```{R, message = FALSE}
knitr::opts_knit$set(root.dir = file.path('..','inst','extdata'))
library(dplyr)
```{R} # Read in Data for the years 2014-2016, the data for 2016 is not actually in the working directory and wil therefore cause a warning. data_list = fars::fars_read_years(list(2014,2016,2015)) # Check that the result is in fact a list of dfs str(data_list) # Check the structure of the dataframe for 2014 str(data_list[1]) # The sequence of the data in the list corresponds to the sequence in which the years where passed and therefore the second entry of this list should be a NULL value str(data_list[2])
fars_summarize_years
Just as fars_read_years
this function takes as input several years. It returns a single dataframe with the monthly accident counts for each year. Again it just skips invalid years with a warning.
This function is used in the following way:
summary = fars::fars_summarize_years(list(2014,2016,2015)) head(summary)
fars_map_state
This function takes as input the number of a state and a year and plots the coordinates of all accidents in that year and state:
This function is used in the following way:
{R, eval = FALSE}
fars::fars_map_state(1,2013)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.