dplyr::rename

rename(.data, ...)
Returns: tibble · Updated April 5, 2026 · Tidyverse
dplyr r tidyverse data-wrangling

rename() changes column names without dropping any columns. Unlike select(), which both selects and optionally renames, rename() keeps every column that was in the input — it only changes the names you specify.

Signature

rename(.data, ...)

Parameters

.data

A data frame, tibble, or lazy data frame (from dbplyr or dtplyr).

Named pairs using new_name = old_name. The new column name goes on the left, the existing name on the right. Uses tidy selection so you can refer to columns bare:

rename(df, new_col = old_col)

Return Value

A tibble with the same rows and columns as the input, with the specified column names changed.

Basic Usage

library(dplyr)

df <- tibble(
  user_id = 1:3,
  user_name = c("Alice", "Bob", "Carol"),
  user_email = c("alice@example.com", "bob@example.com", "carol@example.com")
)

# Rename one column
df |> rename(id = user_id)
#> # A tibble: 3 × 3
#>       id user_name user_email
#>   <int> <chr>    <chr>
#> 1     1 Alice    alice@example.com
#> 2     2 Bob      bob@example.com
#> 3     3 Carol    carol@example.com

Notice the syntax: the new name (id) comes before the old name (user_id). This reads like you’re creating a new variable with the old value.

Renaming Multiple Columns

Pass as many new = old pairs as you need:

df |> rename(
  id = user_id,
  name = user_name,
  email = user_email
)
#> # A tibble: 3 × 3
#>       id name    email
#>   <int> <chr>   <chr>
#> 1     1 Alice   alice@example.com
#> 2     2 Bob     bob@example.com
#> 3     3 Carol   carol@example.com

Renaming with Tidy Selection Helpers

You can use tidy-select helpers on the right-hand side:

# Rename a column using starts_with
df |> rename(id = starts_with("user_i"))

For more complex batch operations, use rename_with().

rename_with — Batch Renaming with Functions

rename_with() applies a function to column names. It’s useful when you want to apply the same transformation to multiple columns:

df <- tibble(
  first_name = c("Alice", "Bob"),
  last_name = c("Smith", "Jones"),
  age = c(30, 25)
)

# Uppercase all column names
df |> rename_with(toupper)
#> # A tibble: 2 × 3
#>   FIRST_NAME LAST_NAME   AGE
#>   <chr>     <chr>     <dbl>
#> 1 Alice     Smith        30
#> 2 Bob       Jones        25

# Prefix specific columns
df |> rename_with(~ paste0("col_", .x), c(first_name, last_name))
#> # A tibble: 2 × 3
#>   col_first_name col_last_name   age
#>   <chr>          <chr>         <dbl>
#> 1 Alice          Smith             30
#> 2 Bob            Jones            25

The .cols argument controls which columns get transformed. Defaults to everything():

# Only transform columns that start with "first" or "last"
df |> rename_with(toupper, .cols = starts_with("first") | starts_with("last"))

rename vs select

Both can rename columns, but they differ:

rename()select()
Drops other columnsNoNo (unless you use -col)
Rename + reorderNoYes
Multiple renamesYesYes

In practice, rename() is cleaner when you want to change some names without thinking about column order. select() is better when you’re also picking which columns to keep and want to reorder them.

See Also