paste2 {DIZtools} | R Documentation |
Normal 'paste' function with additional 'collapse_last' argument.
Description
The base 'paste' function but with the add on to also supply a 'collapse_last' value to change the 'collapse' argument at the last position. To get from "cat", "mouse", "dog" to a string "cat, mouse and dog", one simply needs to call 'paste(c("cat","mouse","dog"), collapse = ", ", collapse_last = " and ")'
Usage
paste2(..., collapse = NULL, collapse_last = NULL, sep = " ", recycle0 = FALSE)
Arguments
... |
one or more R objects, to be converted to character vectors. |
collapse |
an optional character string to separate the results. Not
|
collapse_last |
(string, optional) The string to use for the last instance while collapsing. All other elements will be pasted using the normal 'collapse' argument. If 'collapse' is not set, 'collapse_last' will be ignored. |
sep |
a character string to separate the terms. Not
|
recycle0 |
|
Value
String. See'?paste' for details.
References
https://stackoverflow.com/a/38276239
Examples
{
paste2(c("cat", "mouse", "dog"),
collapse = ", ",
collapse_last = " and ")
#> [1] "cat, mouse and dog"
}