首页 > 解决方案 > 包中的年份::huxtable 表脚注默认为科学概念

问题描述

我正在尝试使用 package::huxtable 在表格中添加一个包含 4 位数年份的脚注。年份以科学计数法输出。我在参考表格正文中的数字和我的问题时遇到了同样的问题 @katia 解释了发生了什么。但现在我被困在试图解决同样的问题,但在表格的脚注中:

options(scipen = 100, digits = 10)
library(huxtable)
t <- huxtable(mtcars[1:5, 1:2])
number_format(t) <- 1
add_footnote(t, "No cars in 1776")

脚注打印为:

# No cars in 1.78e+03

我不知道发生了什么 - number_format() 将整个表格的小数位设置为 1。或者应该是。删除它会将整个表格恢复为科学计数法。将 1776 放在引号中会导致错误:

Error: unexpected numeric constant in "add_footnote(t, "No cars in "1776"

非常感谢任何指针/帮助!

标签: r

解决方案


footnotein ahuxtable带有自己的属性-您可以传递其他参数,然后将其传递给`set_cell_properties

参数
... 其他属性,传递给脚注单元格的 set_cell_properties。

指定number_formatadd_footnote应该工作的附加参数

add_footnote(t, "No cars in 1776", number_format = 0)

  # 21.0           6.0           
  # 21.0           6.0           
  # 22.8           4.0           
  # 21.4           6.0           
  # 18.7           8.0           
# ───────────────────────────────
  # No cars in 1776              

# Column names: mpg, cyl

推荐阅读