chars_to_text: Combine character inputs 'x' into a single string of text.

View source: R/text_util_fun.R

chars_to_textR Documentation

Combine character inputs x into a single string of text.

Description

chars_to_text combines multi-element character inputs x into a single string of text (i.e., a character object of length 1), while preserving punctuation and spaces.

Usage

chars_to_text(x, sep = "")

Arguments

x

A vector (required), typically a character vector.

sep

Character to insert between the elements of a multi-element character vector as input x? Default: sep = "" (i.e., add nothing).

Details

chars_to_text is an inverse function of text_to_chars.

Note that using paste(x, collapse = "") would remove spaces. See collapse_chars for a simpler alternative.

Value

A character vector (of length 1).

See Also

collapse_chars for collapsing character vectors; 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, collapse_chars(), 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

# (a) One string (with spaces and punctuation):
t1 <- "Hello world! This is _A   TEST_. Does this work?"
(cv <- unlist(strsplit(t1, split = "")))
(t2 <- chars_to_text(cv))
t1 == t2

# (b) Multiple strings (nchar from 0 to >1):
s <- c("Hi", " ", "", "there!", " ", "", "Does  THIS  work?")
chars_to_text(s)

# Note: Using sep argument: 
chars_to_text(c("Hi there!", "How are you today?"), sep = "  ")
chars_to_text(1:3, sep = " | ")
 

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