You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R语言gt包在Quarto发布时表头出现?caption错误求助

解决Quarto中gt表格表头出现"?caption"的问题

核心问题:管道连接中断

你的代码中gt::gt()之后没有通过%>%连接后续的表格格式操作,导致所有cols_label、tab_spanner等设置完全没应用到生成的gt表格上,这是引发异常的主要原因。

修正后的关键代码片段

business_segment_summary %>% 
  select(1,n,tar_prop,n_prop,prop_od,prop_25,prop_50,prop_75) %>% 
  gt::gt() %>%  # 补全管道连接
  gt::cols_label(cut="Business Segment",
                 n="Customer #",
                 tar_prop="% of TAR",
                 n_prop="% of Customers",
                 prop_od=gt::html("% of Customers<br>with overdue"),
                 prop_25="25%",
                 prop_50="50%",
                 prop_75="75%") %>% 
  gt::tab_spanner(label="Customer Account Percentile ($k)",columns = c(prop_25,prop_50,prop_75)) %>% 
  gt::fmt_number(c(prop_25,prop_50,prop_75),decimals = 0,scale_by = 1/1e3) %>% 
  gt::fmt_number(n,decimals = 0) %>% 
  gt::fmt_percent(c(3:5),decimals = 0) %>% 
  gt::opt_stylize(style=1,color="red") %>% 
  gt::tab_header(title="Summary of TAR by business segments") %>% 
  gt::cols_align(align="left",columns = 1)

其他排查方向

  • 检查Quarto代码块是否误设置了未赋值的caption参数,比如{r, caption=},这种情况会渲染出"?caption",删除或正确赋值即可
  • 避免gt的tab_caption与Quarto代码块的caption重复设置,防止冲突
  • 更新gt包到最新版本,修复可能存在的版本兼容问题

内容的提问来源于stack exchange,提问作者alejandro_hagan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 09:15:30