collapse_chars: Collapse character inputs 'x' into a single string.

View source: R/text_util_fun.R

collapse_charsR Documentation

Collapse character inputs x into a single string.

Description

collapse_chars converts multi-element character inputs x into a single string of text (i.e., a character object of length 1), separating its elements by sep.

Usage

collapse_chars(x, sep = " ")

Arguments

x

A vector (required), typically a character vector.

sep

A character inserted as separator/delimiter between elements when collapsing multi-element strings of x. Default: sep = " " (i.e., insert 1 space between elements).

Details

As collapse_chars is a wrapper around paste(x, collapse = sep). It preserves spaces within the elements of x.

The separator sep is only used when collapsing multi-element vectors and inserted between elements.

See chars_to_text for combining character vectors into text.

Value

A character vector (of length 1).

See Also

chars_to_text for combining character vectors into text; text_to_chars for splitting text into a vector of characters; text_to_words for splitting text into a vector of words; strsplit for splitting strings.

Other text objects and functions: Umlaut, capitalize(), caseflip(), cclass, chars_to_text(), count_chars_words(), count_chars(), count_words(), invert_rules(), l33t_rul35, map_text_chars(), map_text_coord(), map_text_regex(), metachar, read_ascii(), text_to_chars(), text_to_sentences(), text_to_words(), transl33t(), words_to_text()

Examples

collapse_chars(c("Hello", "world", "!"))
collapse_chars(c("_", " _ ", "  _  "), sep = "|")  # preserves spaces
writeLines(collapse_chars(c("Hello", "world", "!"), sep = "\n"))
collapse_chars(1:3, sep = "")


ds4psy documentation built on Sept. 15, 2023, 9:08 a.m.