【问题标题】:Year in a package::huxtable table footnote is defaulting to scientific notion包中的年份::huxtable 表脚注默认为科学记数法
【发布时间】:2018-05-22 23:59:22
【问题描述】:

我正在尝试使用 package::huxtable 在表格中添加一个包含 4 位数年份的脚注。年份以科学计数法输出。我在参考表格正文中的数字和我的问题here 时遇到了同样的问题,@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


    【解决方案1】:

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

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

    number_format 指定为add_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
    

    【讨论】:

    • 谢谢!这行得通。我尝试使用 format() 进行包装,但没有考虑通过 number_format()。
    猜你喜欢
    • 2018-10-09
    • 2013-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-22
    • 2017-06-06
    • 2020-12-30
    • 2018-07-03
    相关资源
    最近更新 更多