R/StripWhite.r

Defines functions strip_white strip_white.default strip_white.data.frame strip_white.data.table

Documented in strip_white

#' Strips all White Space from character string
#'
#' \code{strip_white} removes all extra spaces from before and after a character string
#'
#' @inheritParams  capitalize
#' @return Object of input class
#' @export

#A. Generic

strip_white <- function(data) {
  UseMethod("strip_white")
}

#' @export
strip_white.default <- function(data) {
  if (is.character(data)){
    stringr::str_trim(data)
  } else {
    stop(paste(quote(data), "is unsupported class:", class(data)))
  }
}

#' @export
strip_white.data.frame <- function(data) {
  data2 <- mutate_if(data, is.character, stringr::str_trim)
	data2
}

#' @export
strip_white.data.table <- function(data) {
  if(!R.utils::isPackageLoaded("dtplyr")){
    stop("Please Load dtplyr for data.table")
  }

  data2 <- mutate_if(data, is.character, stringr::str_trim)
	data2
}
MattKelliher-Gibson/prepr documentation built on March 21, 2020, 3:16 p.m.