Home > Back-end >  flextable: systematically change multiple headers' labels
flextable: systematically change multiple headers' labels

Time:06-03

I'm looking to change the S_1 through S_4 here with a one-liner, instead of typing them all out in set_header_label.

enter image description here`

how I made up ft1

ft1 <- head(iris) %>%
  flextable() %>%
set_header_labels(
  values = list(
    Sepal.Length = "S_1",
    Sepal.Width = "S_2",
    Petal.Length = "S_3",
    Petal.Width = "S_4"
  )
)

The rough idea of the one-liner

ft1 %>%
  set_header_labels(
  values = list(list(S_1:S_4) = list(paste("\U03A3", c(1:4), sep = "_"))))

CodePudding user response:

I think one approach is to create a named list separately, and then use in set_header_labels. Let me know if this is what you were looking for.

my_list <- setNames(as.list(paste0("S_", 1:4)), names(iris[1:4]))

ft1 <- head(iris) %>%
  flextable() %>%
  set_header_labels(values = my_list)
  • Related