Skip to content

Add md() and html() features to list argument in cols_label() #1146

@alex-lauer

Description

@alex-lauer

Prework

Proposal

I really love the feature to add a named list of column labels to cols_label(). In most cases this list evolves during my data processing work prior to the table creation. I would like to use md() here to add a line break to my column labels. The below code works fine:

library(gt)
library(tidyverse)

col_list1 <- list(
  "mfr" = "Manufacturer",
  "model" = "Model",
  "hp_rpm" = md("Horse Power  \n(rpm)")
)

gt::gtcars |> 
  dplyr::filter(mfr == "BMW") |> 
  dplyr::select(mfr, model, hp_rpm) |> 
  gt() |> 
  cols_label(
    .list = col_list1
  )

image

However, these ones don't:

library(gt)
library(tidyverse)

col_list2 <- as.list(c("Manufacturer", "Model", md("Horse Power  \n(rpm)"))) |> 
  purrr::set_names(c("mfr", "model", "hp_rpm"))

gt::gtcars |> 
  dplyr::filter(mfr == "BMW") |> 
  dplyr::select(mfr, model, hp_rpm) |> 
  gt() |> 
  cols_label(
    .list = col_list2
  )

col_list3 <- as.list(c("Manufacturer", "Model", "Horse Power  \n(rpm)")) |> 
  purrr::set_names(c("mfr", "model", "hp_rpm"))

gt::gtcars |> 
  dplyr::filter(mfr == "BMW") |> 
  dplyr::select(mfr, model, hp_rpm) |> 
  gt() |> 
  cols_label(
    .list = md(col_list3)
  )

image

Thanks so much in advance!

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions