The FARS package use data from the US National Highway Traffic Safety Administration's and performs operations on Fatality Analysis Reporting System, which is a nationwide census providing the American public yearly data regarding fatal injuries suffered in motor vehicle traffic crashes.
This package provides the following Fatality Analysis Reporting System (FARS) functions:
fars_read() reads a file in table format, and returns it as an object of the "tbl_df" class, If the file does not exist in the current directory, this function stops execution with an error message. While reading all messages are suppressed. This function imports the functions read_csv() from the readr package, and tbl_df() from the dplyr package.
make_filename() generates the filename for a FARS datafile and takes a year as input and produces a valid FARS filename. Will return a filename with NA if the year parameter cannot be coerced to an integer. It is an internal function used by other functions in this package.
fars_read_years() takes as its only parameter a vector of years, reads the FARS files for those years and returns the Month and Year columns as a list. Invalid years will have a NULL entry in the returned list. This function imports the functions mutate() and select() from the dplyr package and the operator "%>%" from magrittr package.
fars_summarize_years() can be used to get a data frame of FARS data for multiple years. Summarizes the number of fatal injuries suffered in motor vehicle traffic crashes by month with each year in its own column. If no valid years are found, the function will give an error. This function imports the functions bind_rows(), group_by() and summarize() from the dplyr package, spread() from the tidyr package and the operator "%>%" from magrittr package.
fars_map_state() draws the location of accidents in a US State for a given year and takes an integer that represents the state number and a vector of integer or strings that indicated the year of interest. This function draws a map of the State and shows one point for each fatality that occurred in that State. Will throw an error if an invalid state number is chosen or the chosen year's data does not exist. This function imports the functions filter() from dplyr package, map() from maps package and points() from graphics package.
The installation of the FARS package is done using its github repository and the install_github() function in the devtools package.
devtools::install_github("zpopovych/fars", build_vignettes = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.