cleanup_spaces: Clean up the use of whitespace in a character vector

View source: R/utils.R

cleanup_spacesR Documentation

Clean up the use of whitespace in a character vector

Description

The function cleanup_spaces() takes a character vector and input and turns any uninterrupted stretch of whitespace characters into one single space character. Moreover, it can also remove leading whitespace and trailing whitespace.

Usage

cleanup_spaces(x, remove_leading = TRUE, remove_trailing = TRUE)

Arguments

x

Character vector.

remove_leading

Logical. If TRUE, leading whitespace will be removed.

remove_trailing

Logical. If TRUE, trailing whitespace will be removed.

Value

A character vector.

Examples

txt <- "  A \\t  small      example \\n with redundant whitespace    "
cleanup_spaces(txt)
cleanup_spaces(txt, remove_leading = FALSE, remove_trailing = FALSE)

mclm documentation built on Oct. 3, 2022, 9:07 a.m.