R String Concatenation

R gives you several ways to join strings together, from the simple paste() function to the collapse-friendly tools built on top of it.

Why You Can't Just Use +

R does not overload the + operator for text the way some languages do — arithmetic operators only work on numbers. Instead, you combine strings with paste(), which glues its arguments together and inserts a single space between them by default. You can change that gap with the sep argument, or remove it entirely.

Example

first_name <- "Ada"
last_name <- "Lovelace"

paste(first_name, last_name)
# "Ada Lovelace"

paste("2026", "07", "17", sep = "-")
# "2026-07-17"

The Shortcut: paste0()

Setting sep = "" is so common that R gives it its own function: paste0(). paste0(a, b) behaves exactly like paste(a, b, sep = ""), making it the idiomatic choice whenever you want text stuck together with no gap at all.

Example

item <- "apple"
count <- 3
message <- paste0("You have ", count, " ", item, "s")
print(message)
# "You have 3 apples"

filename <- paste0("report_", 2026, ".csv")
# "report_2026.csv"

Concatenating Whole Vectors

paste() is vectorized, so when you hand it vectors of the same length it pairs elements up position by position instead of looping manually. Add the collapse argument when you want the whole result flattened into a single string rather than a character vector.

Example

names <- c("Ana", "Beto", "Chen")
scores <- c(88, 92, 79)

paste(names, "scored", scores)
# "Ana scored 88" "Beto scored 92" "Chen scored 79"

paste(names, collapse = ", ")
# "Ana, Beto, Chen"
FunctionSeparatorBest For
paste()" " (space)General joining with a custom separator
paste0()"" (none)Fast concatenation with no gap
paste(..., collapse = )your choiceFlattening a vector into one string
Note: paste() automatically converts numbers, logicals, and factors to text before joining them, so you rarely need an explicit as.character() call beforehand.