以编程方式将单元格值传递给 GT tab_header 中的标题

programmatically pass cell value to title in GT tab_header

我想使用特定列中的值作为我的 gt 的标题 table。
标题列中的所有行都具有相同的字符值。
如何引用 tab_header

中的列

我想这样做是因为我从一个大数据框中制作了很多 table,每个都有不同的标题

这是示例数据

d <- data.frame(
          organism=c("Grasshopper", "Bumblebee", "MycoTB"), 
          protein=c("Jumpylegs", "venom-1", "rpoB"), 
          accession=c("Gr1,Gr2,Gr3", "Bbv4,Bbv5,Bbv6", "Mtb1,Mtb2,Mtb3,Mtb4,Mtb5"), 
          title = c("mytitle", "mytitle", "mytitle")
)

这是我的代码

d %>%
          gt() %>%
          tab_header(
                    title = # here I want to get the text from the title column, somthing like .$title[1]
                
          )
d %>%
  gt() %>%
  tab_header(
    title = .$`_data`$title[1]
  )

当您将数据转换为 gt 对象时,您可以使用 _data.

访问列表中的数据元素

这给了我们: