modify header label using flextable in user defined function


I'm having trouble modifying header labels when using flextable within a user defined function. As shown below, set_header_labels(mpg = "Miles/Gallon") modifies the header label, but not when I attempt to wrap it into a function. Any advice for how to do so would be greatly appreciated.


# make a flextable and modify header label
mtcars %>% 
  head() %>% 
  flextable() %>% 
  set_header_labels(mpg = "Miles/Gallon")
# create function
tab_fun <- function(df, tab_var, var_lab) {
  df %>% 
    head() %>% 
    flextable() %>%
    set_header_labels(tab_var = var_lab)

# header label not modified
mtcars %>% tab_fun(mpg, "Miles/Gallon")

Created on 2022-04-08 by the reprex package (v2.0.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.