#' @title Remove redundant white space.
#' @description
#' Remove whitespace from a character or vector. Note that this will always return a character.
#'
#' @param x is the value to be trimmed
#' @return a value without any extra whitespace
#' @export
#' @examples
#' trim('This value has an unnecessary amount of whitespace ')
#'
#' ## Performing the trim function on a vector
#' iris$Species <- paste(iris$Species,' Species',sep='')
#' head(iris)
#' ## Correct the whitespacing
#' iris$Species <- trim(iris$Species)
#' ## View our corrected dataframe
#' head(iris)
#' rm(iris)
#'@import stringr
trim <- function(x) {
#require(stringr)
requireNamespace("stringr", quietly = TRUE)
x <- gsub(" ", " ", x)
x <- gsub(" ", " ", x)
x <- gsub(" ", " ", x)
x <- gsub(" ", " ", x)
x <- str_trim(x, side = c("both"))
return(x)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.