Learn R Programming

stringr (version 0.6.2)

str_c: Join multiple strings into a single string.

Description

To understand how str_c works, you need to imagine that you are building up a matrix of strings. Each input argument forms a column, and is expanded to the length of the longest argument, using the usual recyling rules. The sep string is inserted between each column. If collapse is NULL each row is collapsed into a single string. If non-NULL that string is inserted at the end of each row, and the entire matrix collapsed to a single string.

Usage

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

Arguments

...
one or more character vectors. Zero length arguments are removed
sep
string to insert between input vectors
collapse
optional string used to combine input vectors into single string

Value

  • If collapse = NULL (the default) a character vector with length equal to the longest input string. If collapse is non- NULL, a character vector of length 1.

See Also

paste which this function wraps

Examples

Run this code
str_c("Letter: ", letters)
str_c("Letter", letters, sep = ": ")
str_c(letters, "is for", "...")
str_c(letters[-26], "comes before ", letters[-1])

str_c(letters, collapse = "")
str_c(letters, collapse = ", ")

Run the code above in your browser using DataLab