R/trim.R

Defines functions rtrim ltrim trim

Documented in ltrim rtrim trim

#' Trim
#'
#' Trim both leading and trailing whitespaces from string.
#'
#' @param x A text string.
#' @return Cleaned string.
#' @examples
#' trim(" hello ")
#'
#' @export
trim <- function(x) gsub("^\\s+|\\s+$", "", x)

#' LTrim
#'
#' Trim leading whitespace from sting.
#' @param x A text string.
#' @return Cleaned string.
#' @examples
#' trim(" hello")
#' @export
ltrim <- function(x) gsub("^\\s+", "", x)

#' RTrim
#'
#' Trim trailing whitespaces from string.
#' @param x A text string.
#' @return Cleaned string.
#' @examples
#' trim("hello ")
#' @export
rtrim <- function(x) gsub("\\s+$", "", x)

Try the vvconverter package in your browser

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

vvconverter documentation built on June 22, 2024, 10:53 a.m.