rename_like: Rename names that match a regular expression

rename_likeR Documentation

Rename names that match a regular expression

Description

Rename names that match a regular expression

Usage

rename_like(
  x,
  pattern,
  f,
  ...,
  ignore.case = FALSE,
  perl = FALSE,
  fixed = FALSE,
  useBytes = FALSE
)

Arguments

x

An object with names.

pattern

A regular expression string (see regex).

f

A function, one-sided formula, or character vector.

...

Passed into f. An error is thrown if ... is non-empty when f is a character vector.

ignore.case, perl, fixed, useBytes

Passed into grepl().

Details

  • If f is a function it will be applied to the selected names. If it is a formula and the 'rlang' package is installed, it will be converted to a function by rlang::as_function(), then applied.

  • If f is a named character vector like c(new_name = "old_name", ...) then "old_name" will become "new_name", as in dplyr::rename().

  • If f is an unnamed character vector, these will be the new names in order.

Value

The renamed object.

Examples


vec <- c("One" = 1, "Two" = 2, "Three" = 3, "Four" = 4)
rename_like(vec, "^T", paste0, "x")


hughjonesd/rumpel documentation built on Jan. 22, 2025, 1:12 a.m.