rename_remove_prefix: Remove a prefix or suffix from names

rename_remove_prefixR Documentation

Remove a prefix or suffix from names

Description

Remove a prefix or suffix from names

Usage

rename_remove_prefix(x, prefix)

rename_remove_suffix(x, suffix)

Arguments

x

An object with names.

prefix, suffix

A length 1 character vector to remove.

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

x with the prefix or suffix removed from names(x).

Examples


vec <- c("a.1" = 1, "aaa.1" = 2, "other" = 3, ".1" = 4)
vec |> rename_remove_suffix(".1")

vec <- c("x.a" = 1, "x.aaa" = 2, "other" = 3, "x." = 4)
vec |> rename_remove_prefix("x.")

hughjonesd/namer documentation built on Jan. 23, 2025, 5:28 p.m.