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

Description Usage Arguments Value Examples

Description

The function cleanup_spaces takes as its input a character vector x, and returns a copy of x in which the use of whitespace characters has been ‘normalized’. More specifically, this ‘normalization’ entails that each uninterrrupted stretch of whitespace characters, i.e. each sequence of one or more consecutive whitespace characters, is replaced by a single SPACE character. Moreover, in case of the argument specification remove_leading = TRUE, all leading whitespace is removed, and in case of the argument specification remove_trailing = TRUE, all trailing whitespace is removed.

Usage

1
2
3
cleanup_spaces(x,
               remove_leading = TRUE,
               remove_trailing = TRUE)

Arguments

x

the argument x contains the character vector to which the cleaning up has to be applied.

remove_leading

in case of the setting remove_leading = TRUE, all leading whitespace is completely removed; in case of the setting remove_leading = FALSE, any leading whitespace is ‘normalized’, as explained above, but not completely removed.

remove_trailing

in case of the setting remove_trailing = TRUE, all trailing whitespace is completely removed; in case of the setting remove_trailing = FALSE, any trailing whitespace is ‘normalized’, as explained above, but not completely removed.

Value

Returns a character vector that is a copy of x in which all whitespace is ‘normalized’.

Examples

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

wai-wong-reimagine/mclm documentation built on May 16, 2019, 9:12 p.m.