Examples for 'stringr::str_flatten'


Flatten a string

Aliases: str_flatten str_flatten_comma

Keywords:

### ** Examples

str_flatten(letters)
[1] "abcdefghijklmnopqrstuvwxyz"
str_flatten(letters, "-")
[1] "a-b-c-d-e-f-g-h-i-j-k-l-m-n-o-p-q-r-s-t-u-v-w-x-y-z"
str_flatten(letters[1:3], ", ")
[1] "a, b, c"
# Use last to customise the last component
str_flatten(letters[1:3], ", ", " and ")
[1] "a, b and c"
# this almost works if you want an Oxford (aka serial) comma
str_flatten(letters[1:3], ", ", ", and ")
[1] "a, b, and c"
# but it will always add a comma, even when not necessary
str_flatten(letters[1:2], ", ", ", and ")
[1] "a, and b"
# str_flatten_comma knows how to handle the Oxford comma
str_flatten_comma(letters[1:3], ", and ")
[1] "a, b, and c"
str_flatten_comma(letters[1:2], ", and ")
[1] "a and b"

[Package stringr version 1.5.1 Index]