How to Add Column Labels When Piping in R with dplyr and labelled?

262 Views Asked by At

Is it possible to create column labels while piping in R with dplyr? E.g. something like:

df <- mtcars %>% 
  some_lovely_function_for_labels(mpg = 'Miles per gallon')

Perhaps the solution could work for a list of variable-labels pairs.

I've explored the labelled package to no avail.

1

There are 1 best solutions below

0
On

Followed the link provided by I_O and learned about the package Hmisc. The following seems to work:

df <- mtcars %>% 
  Hmisc::upData(labels = c(mpg = 'Miles per gallon'))