R/remove_extra_spaces.R

Defines functions remove_extra_spaces

Documented in remove_extra_spaces

#' Trim extra white-spaces from strings
#'
#' Removes unnecessary white-spaces from the left, right and/or interior of
#' strings.
#' @param x A character vector.
#'
#' @return A character vector.
#' @export
#' @examples
#' x. <- c(" San  Sebastian ")
#' remove_extra_spaces(x.)
remove_extra_spaces <- function(x) {
  stopifnot(is.character(x))

  x <- gsub("\\s{2,}", " ", x)
  x <- gsub("^\\s+|\\s$", "", x)
  x
}
GuillermoNasarre/limpyr documentation built on Dec. 17, 2021, 10:25 p.m.