Skip to content

@rename

Renaming colummns follows the same syntax as in R's tidyverse, where the "tidy expression" is new_name = old_name. While the main function to rename columns is @rename(), you can also use @select() if you additionally plan to select only the renamed columns.

using Tidier
using RDatasets

movies = dataset("ggplot2", "movies");

Rename using @rename()¤

If you only want to rename the columns without selecting them, then this is where @rename() comes in handy. For the sake of brevity, we are selecting the first 5 columns and rows after performing the @rename().

@chain movies begin
    @rename(title = Title, Minutes = Length)
    @select(1:5)
    @slice(1:5)
end
5×5 DataFrame
RowtitleYearMinutesBudgetRating
StringInt32Int32Int32?Float64
1$1971121missing6.4
2$1000 a Touchdown193971missing6.0
3$21 a Day Once a Month19417missing8.2
4$40,000199670missing8.2
5$50,000 Climax Show, The197571missing3.4

Rename using @select()¤

If you plan to only select those columns that you would like to rename, then you can use @select() to both rename and select the columns of interest.

@chain movies begin
  @select(title = Title, Minutes = Length)
  @slice(1:5)
end
5×2 DataFrame
RowtitleMinutes
StringInt32
1$121
2$1000 a Touchdown71
3$21 a Day Once a Month7
4$40,00070
5$50,000 Climax Show, The71

This page was generated using Literate.jl.