R/test_white_spaces.R

#' test_for_white_spaces
#'
#' Tests white spaces that could end up padding text
#' @param text Input text. Usually this would be a \code{character} field.
#' @export
#' @examples \dontrun{
#' test_white_spaces(" Karthik Ram")
#' test_white_spaces(" Karthik Ram ")
#'}
test_white_spaces <- function (text) 
{     
    wsDetected <- FALSE
    text1 <- sub("^ +", "", text)
    if (text1 != text) {
      wsDetected <- TRUE
    }
    text2 <- sub(" +$", "", text)
    if (text2 != text) {
      wsDetected <- TRUE
    } 
    wsDetected
}
ropensci/testdat documentation built on May 27, 2019, 7:32 p.m.