These are methods for the dplyr generics dplyr::rename() and dplyr::rename_with().
They are both translated to data.table::setnames().
# S3 method for class 'dtplyr_step'
rename(.data, ...)
# S3 method for class 'dtplyr_step'
rename_with(.data, .fn, .cols = everything(), ...)For rename(): <tidy-select> Use
new_name = old_name to rename selected variables.
For rename_with(): additional arguments passed onto .fn.
A function used to transform the selected .cols. Should
return a character vector the same length as the input.
<tidy-select> Columns to rename;
defaults to all columns.
library(dplyr, warn.conflicts = FALSE)
dt <- lazy_dt(data.frame(x = 1, y = 2, z = 3))
dt %>% rename(new_x = x, new_y = y)
#> Source: local data table [1 x 3]
#> Call: setnames(copy(`_DT34`), c("x", "y"), c("new_x", "new_y"))
#>
#> new_x new_y z
#> <dbl> <dbl> <dbl>
#> 1 1 2 3
#>
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results
dt %>% rename_with(toupper)
#> Source: local data table [1 x 3]
#> Call: setnames(copy(`_DT34`), toupper)
#>
#> X Y Z
#> <dbl> <dbl> <dbl>
#> 1 1 2 3
#>
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results