Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

stri_flatten

Flatten a String


Description

Joins the elements of a character vector into one string.

Usage

stri_flatten(str, collapse = "", na_empty = FALSE, omit_empty = FALSE)

Arguments

str

a vector of strings to be coerced to character

collapse

a single string denoting the separator

na_empty

single logical value; should missing values in str be treated as empty strings?

omit_empty

single logical value; should missing values in str be omitted?

Details

The stri_flatten(str, collapse='XXX') call is equivalent to paste(str, collapse='XXX', sep='').

If you wish to use some more fancy (e.g., differing) separators between flattened strings, call stri_join(str, separators, collapse='').

If str is not empty, then a single string is returned. If collapse has length > 1, then only the first string will be used.

Value

Returns a single string, i.e., a character vector of length 1.

See Also

Other join: %s+%(), stri_dup(), stri_join_list(), stri_join()

Examples

stri_flatten(LETTERS)
stri_flatten(LETTERS, collapse=',')
stri_flatten(stri_dup(letters[1:6], 1:3))
stri_flatten(c(NA, '', 'A', '', 'B', NA, 'C'), collapse=',', na_empty=TRUE, omit_empty=TRUE)

stringi

Character String Processing Facilities

v1.6.1
file LICENSE
Authors
Marek Gagolewski [aut, cre, cph] (<https://orcid.org/0000-0003-0637-6028>), Bartek Tartanus [ctb], and others (stringi source code); IBM, Unicode, Inc. and others (ICU4C source code, Unicode Character Database)
Initial release
2021-05-05

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.