带有条件字体颜色的kablextra在正确位置不正确绘制正确的颜色
我在data.table中有一个以下基因列表表;
t.mini
cluster1 cluster15 cluster31
<fctr> <fctr> <fctr>
1: Slc6a6 Cd8a Retnla
2: Sema3g Cd8b1 Cxcl15
3: Cyp26b1 Pdcd1 Scgb3a2
4: H2-Q6 Cd3g Sftpb
5: Klhl5 Sh2d2a Scgb1a1
6: Dnah8 Cxcr6 Sftpa1
7: Tm4sf1 Cd3e Cbr2
8: Cdc42bpb Rgs16 Sftpd
9: Cxcl12 Nkg7 Wfdc2
10: Sptan1 Ms4a4b Cyp2f2
我想通过使用KableExtra将任何CXCL基因的字体颜色输出为红色,然后提出了以下代码;
lapply(1:3, function(y) {
kbl(t.mini) |>
kable_classic_2(full_width=F) |>
column_spec(column = y, color = fifelse(unlist(t.mini[, lapply(.SD, function(x){grepl(glob2rx("Cx*"), x)})]), "red", "black"))
})
但是,所得表的红色字体不仅映射到了错误的基因,而且只有一个基因。
任何指针都将不胜感激。
I have a following gene list table in the data.table;
t.mini
cluster1 cluster15 cluster31
<fctr> <fctr> <fctr>
1: Slc6a6 Cd8a Retnla
2: Sema3g Cd8b1 Cxcl15
3: Cyp26b1 Pdcd1 Scgb3a2
4: H2-Q6 Cd3g Sftpb
5: Klhl5 Sh2d2a Scgb1a1
6: Dnah8 Cxcr6 Sftpa1
7: Tm4sf1 Cd3e Cbr2
8: Cdc42bpb Rgs16 Sftpd
9: Cxcl12 Nkg7 Wfdc2
10: Sptan1 Ms4a4b Cyp2f2
I would like to output the table with the font color of any Cxcl genes to red by using kableextra, and I came up with a code as follows;
lapply(1:3, function(y) {
kbl(t.mini) |>
kable_classic_2(full_width=F) |>
column_spec(column = y, color = fifelse(unlist(t.mini[, lapply(.SD, function(x){grepl(glob2rx("Cx*"), x)})]), "red", "black"))
})
However, the resulting table has red font mapped not only to a wrong gene but only one gene as in this table.
Any pointers will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
cell_spec
并首先将数据传递到kbl
可以工作 -Using
cell_spec
and transforming the data first before passing it tokbl
can work -