collapse {utilitiesR}R Documentation

Convenience wrapper that concatenates a vector into a string.

Description

This is mainly used to concatenate elements of a vector into a string. It is just a wrapper around paste with collapse=”, so if you find yourself specifying both sep and collapse to collapse, just use paste instead!

Usage

  collapse(..., sep = "", collapse = "")

Arguments

...

vector/string(s) to paste, see paste

sep

string to separate corresponding terms in the arguments in .... Default ”. See paste.

collapse

string to separate each element of the result vector. Default ”. See paste.

Value

the input strings collapsed and pasted.

See Also

%+%, shorthand for pasting with separator ”.

Examples

collapse(letters) # "abcdefghijklmnopqrstuvwxyz"
collapse(letters[1:10], collapse='|') # "a|b|c|d|e|f|g|h|i|j"
collapse(letters[1:10], 1:10) # "a1b2c3d4e5f6g7h8i9j10"
collapse(letters[1:10], 1:10, sep='.') # "a.1b.2c.3d.4e.5f.6g.7h.8i.9j.10"
# Note - if you supply both collapse and sep then you may as well use paste.

[Package utilitiesR version 2.0 Index]