name: Modify the name of an object and return the renamed object

View source: R/strings.R

nameR Documentation

Modify the name of an object and return the renamed object

Description

This function is well suited to modifying the name of an object in a pipeline. It can be thought of as the verb corresponding to the noun 'names'. Convenient functions to modify names using regular expressions are spida2::sub_ and spida2::gsub_. See also uname.

Usage

name(x, nam = x, ...)

col_name(x, nam = x, ...)

row_name(x, nam = x, ...)

Arguments

x

object to be named or renamed with a 'names', 'colnames' or 'rownames' attribute

nam

vector of names or a function

...

additional arguments to used by nam if it is a function

Value

x with a modified name. If nam is a function then the names attribute is modified with names(x) <- nam(names(x), ...).

Examples

## Not run: 
x <- as.list(letters[1:3])
x
name(x)
library(magrittr)
x %>% name %>% name(toupper)
x %>% name %>% name(sub_, '(.*)', 'time_\\1')

## End(Not run)

gmonette/spida2 documentation built on Aug. 11, 2024, 7:52 p.m.