R/reportables_checker.R

#' @title reportables_checker
#'
#' @description Function to check that format of "Title" is correct.
#'
#' @param filepath Filepath of Excel Workbook containing Quarterly Reportable Events.
#'
#' @return Returns dataframe containing call area, complaint number, and corresponding
#' row number in excel sheet. User must determine which are incorrect and fix in Excel
#' sheet.
#'
#' @export

reportables_checker <- function(
  filepath
) {

  data <- openxlsx::read.xlsx(
    xlsxFile = filepath,
    sheet = 'query_export_results(1)',
    startRow = 2
  )

  split <- strsplit(data$Title, ' ')

  data$`Complaint Number` <- as.character(lapply(split, function(x) x[2]))
  data$callarea <- as.character(lapply(split, function(x) x[4]))

  wronglength <- unlist(lapply(split, function(x) length(x) != 6))

  data %<>%
    dplyr::mutate(
      Excel_Row = 1:nrow(.) + 2,
      Check = ifelse(wronglength, 1, 0)
    ) %>%
    dplyr::select(
      `Complaint Number`,
      callarea,
      Excel_Row,
      Check
    )

  return(data)
}
kimjam/srms documentation built on May 20, 2019, 10:21 p.m.