Learn R Programming

seplyr (version 1.0.4)

rename_se: rename standard interface.

Description

rename columns (much different syntax than rename_at). All left hand sides are new column names and all right hand sides are old column names ( this allows swaps).

Usage

rename_se(.data, mapping, splitTerms = TRUE, env = parent.frame())

Arguments

.data

data.frame

mapping

named character vector of columns to rename (new names on the left, original names on the right; this may seem reversed but it matches dplyr::rename()).

splitTerms

logical, if TRUE into separate renames (if FALSE instead, pass all at once to dplyr).

env

environment to work in.

Value

.data with renamed columns

Details

Note: this method as the default setting splitTerms = TRUE, which is safer (avoiding certain known dplyr/dblyr issues) (please see the side-notes of https://winvector.github.io/FluidData/partition_mutate.html for some references).

See Also

rename, rename_at, :=

Examples

Run this code
# NOT RUN {

datasets::mtcars %.>%
   rename_se(., c("cylinders" := "cyl", "gears" := "gear")) %.>%
   head(.)
# # same as:
# datasets::mtcars %>%
#    rename(cylinders = cyl, gears = gear) %>%
#    head()

# rename_se allows column swaps
data.frame(a = 1, b = 2) %.>%
   rename_se(., c('a', 'b') := c('b', 'a'))

# }

Run the code above in your browser using DataLab