paste()

paste(..., sep = " ", collapse = NULL, recycle0 = FALSE)
Returns: character · Updated March 13, 2026 · Base Functions
strings concatenation character base

The paste() function concatenates its arguments after converting them to character strings. Unlike paste0(), it inserts a separator between elements.

Syntax

paste(..., sep = " ", collapse = NULL, recycle0 = FALSE)

Parameters

ParameterTypeDefaultDescription
...objectsObjects to concatenate, coerced to character
sepcharacter" "Separator string inserted between arguments
collapsecharacterNULLOptional string to collapse result into single string
recycle0logicalFALSEIf TRUE, zero-length arguments return NA instead of empty string

Examples

Basic concatenation

paste("Hello", "World")
# [1] "Hello World"

# Using a custom separator
paste("Hello", "World", sep = "-")
# [1] "Hello-World"

Working with vectors

# Each element is concatenated
paste(c("a", "b"), c("1", "2"))
# [1] "a 1" "b 2"

# Separator is recycled
paste(c("x", "y"), 1:3, sep = "_")
# [1] "x_1" "y_2" "x_3"

Collapsing into a single string

words <- c("apple", "banana", "cherry")

# Collapse into one string
paste(words, collapse = ", ")
# [1] "apple, banana, cherry"

# Combine vectors then collapse
paste(c("A", "B"), c("1", "2"), collapse = "-")
# [1] "A 1-B 2"

Difference from paste0()

# paste0 is equivalent to sep = ""
paste0("Hello", "World")
# [1] "HelloWorld"

paste("Hello", "World", sep = "")
# [1] "HelloWorld"

Common Patterns

Building file paths

folder <- "data"
file <- "file.csv"
paste(folder, file, sep = "/")
# [1] "data/file.csv"

# Using file.path() is preferred for paths
file.path(folder, file)
# [1] "data/file.csv"

Creating labels

paste("Item", 1:5, sep = "_")
# [1] "Item_1" "Item_2" "Item_3" "Item_4" "Item_5"

Combining with apply

df <- data.frame(x = 1:3, y = c("a", "b", "c"))
apply(df, 1, paste, collapse = ":")
# [1] "1:a" "2:b" "3:c"

See Also