This package is a Peer-graded Assignment: Building an R Package.

Data Reading, Summarization and Visualization Tool for US National Highway Traffic Safety Administration's Fatality Analysis Reporting System (FARS).

In the following, all functions contained are described.

Reading Data

Helper Functions

These functions are not designed for direct user interaction. As a design choice, they should not be exported to the last user.

make_filename

make_filename is a simple helper function which maps a specified year to its corresponding filename in the package structure.

It is a helper function for fars_read_years andfars_map_state. There are no error handling.

If a NULL object entered, character(0) is returned.

Examples

make_filename("2015")

make_filename(2014)

fars_read_years

fars_read_years is a simple helper function which reads FARS files with specified year and clean record structure to be reported with fars_summarize_years. }

It is a helper function for fars_summarize_years.

If any of the objects requested via input is not available as a year file or is not coercible to integer an "invalid year" error message returns.

Examples

fars_read_years("2015")

fars_read_years(c(2013.0,2014))

User Interface

fars_read - Reading Data

fars_read is a simple wrapper function for reading Comma-seperated Value (CSV) files with basic file handling and limited user interaction.

In case the file does not exist an error message is produced and execution stops.

Examples

fh<-fars_read("accident_2013.csv.bz2")

fars_summarize_years - Summarizing Data

fars_summarize_years creates a summary table with counts of number of records for each month in a specified years.

Examples

fars_summarize_years("2015")

fars_summarize_years(c(2013.0,2014))

fars_map_state - Visualizing Data

fars_map_state is function for plotting a map of the count of accidents in a specific state in a specific year.

fars_map_state function assumes that there will be a single integer value for state.num and single integer value for year. The implementation do not specifically check for these constraints.

If state does not exist in queried year: a error message of "nothing to draw: all regions out of bounds" apprears.

If multiple states will be entered as a vector: a warning message will appear stating "only the first element will be used", on the other hand, the graph will be created properly including all states inputted.

If an empty vector of states is inputted: an error message of "argument is of length zero" wil be displayed

If a non-existing year is entered: an error message of "Error in fars_read(filename) :" will be displayed.

If multiple years will be entered as a vector: an error message of "EXPR must be a length 1 vector" will be displayed.

If an empty vector of years is inputted: an error message of "argument is of length zero" wil be displayed

Examples

fars_map_state(1,2013)

fars_map_state("1",2013.0)



umutkahramankaptan/farspkg documentation built on May 8, 2019, 1:24 p.m.