other-resources: Other useful resources for manipulating names

other-resourcesR Documentation

Other useful resources for manipulating names

Description

There are several existing functions for working with names in R.

Details

Obviously, base::names() gets an object's names and ⁠names<-⁠ sets them.

stats::setNames() directly returns the object after setting names.

base::make.names() turns a character vector into syntactically valid names. vctrs::vec_as_names() does the same thing, r-lib style.

base::make.unique() makes elements of a character vector unique by appending sequence numbers to duplicates.

rlang::set_names() is like setNames() but also takes a function to transform names.

rlang::names2() is like names() but returns a character vector of "" rather than NULL if an object has no names attribute.

dplyr::rename() and friends change the names of data frames or tibbles, but not other objects.

https://principles.tidyverse.org/names-attribute.html is a principled framework for thinking about names in R.


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