R/trim.R

#' @title
#' Removes extra whitespaces from a string
#'
#' @description
#' The function \code{trim} removes unnecessary whitespaces
#' from a character vector.
#'
#' @param x
#' character. The character vector at stake.
#'
#' @return
#' A character vector of the same length as \code{x}.
#'
#' @seealso \code{\link{gsub}}.
#'
#' @export
#'
#' @examples
#' trim(c(" a b", "Hello  World "))
#'
trim <-
function (x)
{
  gsub("^\\s+|\\s+$", "", x)
}

Try the bazar package in your browser

Any scripts or data that you put into this service are public.

bazar documentation built on May 2, 2019, 7:02 a.m.