paste0()

paste0(..., collapse = NULL)
Returns: character · Updated March 13, 2026 · Base Functions
strings concatenation base

paste0() concatenates strings end-to-end, unlike paste() which inserts a space by default. It’s the fastest way to join strings in R when you don’t need a separator.

Syntax

paste0(..., collapse = NULL)

Parameters

ParameterTypeDefaultDescription
...anyObjects to convert to character and concatenate
collapsecharacterNULLOptional string to collapse the result into a single string

Examples

Basic usage

# No separator between elements
paste0("Hello", "World")
# [1] "HelloWorld"

# Multiple strings
paste0("a", "b", "c")
# [1] "abc"

Combining with vectors

# Vectorized - recycles shorter vectors
prefix <- "file"
nums <- 1:3
paste0(prefix, nums)
# [1] "file1" "file2" "file3"

# Collapse into single string
files <- c("data.csv", "model.rds", "output.png")
paste0(files, collapse = ", ")
# [1] "data.csv, model.rds, output.png"

Creating names dynamically

# Generate column names
cols <- c("age", "score", "rank")
paste0(cols, "_new")
# [1] "age_new" "score_new" "rank_new"

# Create file paths
folder <- "output/"
file <- "results"
ext <- ".csv"
paste0(folder, file, ext)
# [1] "output/results.csv"

Common Patterns

Building SQL queries:

table <- "users"
col <- "name"
query <- paste0("SELECT ", col, " FROM ", table)

Dynamic variable names:

prefix <- "result"
for (i in 1:3) {
  assign(paste0(prefix, i), i * 10)
}

See Also