seplyr is an attempt to work with the dplyr 0.7.* R package through standard evaluation interfaces with a minimum of change and minimum of cognitive friction. Beyond championing standard evaluation it attempts to introduce as few of its own opinions as possible.

A case in point is dplyr::rename()/seplyr::rename_se(). dplyr::rename() is used as follows.


datasets::mtcars %>%
  rename(cylinders = cyl, gears = gear) %>%

Notice dplyr::rename() renamings are written as assignments making them very similar to dplyr::mutate(). This is the reverse from how R usually handles list or mapping structures. In named vectors or named lists keys are written on the left and values are written on the right as follows.

mp <- c("cyl" = "cylinders", "gear" = "gears")

Because seplyr is intended to be a set of adapters for dplyr we simply adopt dplyr::rename()'s convention. This allows the user to mechanically translate their experience and expectations from scripting over dplyr::rename() to directly use seplyr::rename_se() as follows.


datasets::mtcars %.>%
  rename_se(., c("cylinders" := "cyl", "gears" := "gear")) %.>%

We hope this makes it easy to translate one-off analyses into re-usable scripts by incrementally replacing known variable names with parametric versions. The := operator is just a convenience function for building up maps, we could also have written rename_se(c("cylinders" = "cyl", "gears" = "gear")) or passed in a named vector built up elsewhere.

rename_se interprets all left-hand names as new column names and all right-hand names as old column names. This allows rename_se to be used to swap columns:

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

Please see help("%.>%", package="wrapr") for details on "dot pipe."

Try the seplyr package in your browser

Any scripts or data that you put into this service are public.

seplyr documentation built on Sept. 5, 2021, 5:12 p.m.