R/eq_location_clean.R

#' Import and clean NOAA data for use in analytics and visualization
#'
#' This function will be used to remove the country name from the LOCATION_NAME
#' field of the NOAA data. This is intended to be used within the \code{eq_data_clean}
#' function, but will ultimately parse any text that is separated by a \code{:}. I originally
#' embeded this code directly in \code{eq_data_clean}, but the instructions clearly require
#' two functions. And thus, here it is.
#'
#' @param dataframe A \code{data.frame} of NOAA data that has been read in
#' already that has a column named LOCATION_NAME.
#'
#' @importFrom stringr str_to_title
#' @importFrom stringr str_split
#' @importFrom stringr str_trim
#' @export
#'
#' @examples
#' \dontrun{
#' #This function really shouldn't be used by yourself. It is only a support to the other function.
#' eq_location_clean(dataframe=data)
#' }
#'

eq_location_clean<-function(dataframe){

  #Rip the country name out of the Location name and camel case it
  #Depended on assumption that ":  " will separates Country and Location
      stringr::str_trim(stringr::str_to_title(stringr::str_split(string=dataframe$LOCATION_NAME,
                                            pattern=": {2}",
                                            simplify=TRUE)[,2]),side="both")}
JJNewkirk/NOAAEQ documentation built on May 27, 2019, 1:12 p.m.