“save_kable as pdf changes structure” 可以翻译为 “将 kable 保存为 PDF 会改变结构”。

huangapple go评论56阅读模式
英文:

save_kable as pdf changes structure

问题

我使用以下代码创建了一个表格:

df %>%
    mutate_if(is.numeric, round, digits = 2) %>%
    kable(format = "simple", caption = "统计评估") %>%
    save_kable(file = "test.pdf")

你知道如何修复这个问题吗?是否有替代方法?

编辑: 这是数据:

structure(list(TPR = c(0.934842767295597, 0.92922841571852), 
    FPR = c(0.516589250165893, 0.525067529460655), ACC = c(0.867615330138182, 
    0.866211826128489), FAR = c(0.0881670095698295, 0.0834131044726853
    ), CSI = c(0.85734568558549, 0.856776377557092), BS = c(1.02523463957426, 
    1.01379194951716), HSS = c(0.444709565304963, 0.419220178831526
    ), tr = c(0.22, 0.25)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -2L))

这是生成的PDF图像:

“save_kable as pdf changes structure” 可以翻译为 “将 kable 保存为 PDF 会改变结构”。

英文:

I created a table using

df %>%  
    mutate_if(is.numeric,round,digits = 2) %>%
    kable(format="simple", caption="Statistical evaluation")  %>%
    save_kable(file="test.pdf")

Do you know how to fix this? Is there an alternative?

EDIT: This is the data

structure(list(TPR = c(0.934842767295597, 0.92922841571852), 
    FPR = c(0.516589250165893, 0.525067529460655), ACC = c(0.867615330138182, 
    0.866211826128489), FAR = c(0.0881670095698295, 0.0834131044726853
    ), CSI = c(0.85734568558549, 0.856776377557092), BS = c(1.02523463957426, 
    1.01379194951716), HSS = c(0.444709565304963, 0.419220178831526
    ), tr = c(0.22, 0.25)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -2L))

and this the pdf
“save_kable as pdf changes structure” 可以翻译为 “将 kable 保存为 PDF 会改变结构”。

答案1

得分: 1

这可以完全在kableExtra中完成。对于PDF输出,通常需要使用format = "latex"。如果您想编辑表格的外观,kableExtra有很多选项。

df1 <- structure(list(TPR = c(0.934842767295597, 0.92922841571852), 
                      FPR = c(0.516589250165893, 0.525067529460655), ACC = c(0.867615330138182, 
                                                                             0.866211826128489), FAR = c(0.0881670095698295, 0.0834131044726853
                                                                             ), CSI = c(0.85734568558549, 0.856776377557092), BS = c(1.02523463957426, 
                                                                                                                                     1.01379194951716), HSS = c(0.444709565304963, 0.419220178831526
                                                                                                                                     ), tr = c(0.22, 0.25)), class = c("tbl_df", "tbl", "data.frame"
                                                                                                                                     ), row.names = c(NA, -2L))

library(kableExtra)

df1 |&gt; 
  kable(format = "latex",
        digits = 2,
        caption="Statistical evaluation")  |&gt; 
  save_kable(file="test.pdf")

创建于2023-06-29,使用reprex v2.0.2

“save_kable as pdf changes structure” 可以翻译为 “将 kable 保存为 PDF 会改变结构”。

英文:

This can be done entirely in kableExtra. For pdf output typically you do need format = &quot;latex&quot;. If you want to edit the appearance of the table kableExtra has plenty of options.

df1 &lt;- structure(list(TPR = c(0.934842767295597, 0.92922841571852), 
                      FPR = c(0.516589250165893, 0.525067529460655), ACC = c(0.867615330138182, 
                                                                             0.866211826128489), FAR = c(0.0881670095698295, 0.0834131044726853
                                                                             ), CSI = c(0.85734568558549, 0.856776377557092), BS = c(1.02523463957426, 
                                                                                                                                     1.01379194951716), HSS = c(0.444709565304963, 0.419220178831526
                                                                                                                                     ), tr = c(0.22, 0.25)), class = c(&quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;
                                                                                                                                     ), row.names = c(NA, -2L))


library(kableExtra)

df1 |&gt; 
  kable(format = &quot;latex&quot;,
        digits = 2,
        caption=&quot;Statistical evaluation&quot;)  |&gt; 
  save_kable(file=&quot;test.pdf&quot;)

<sup>Created on 2023-06-29 with reprex v2.0.2</sup>

“save_kable as pdf changes structure” 可以翻译为 “将 kable 保存为 PDF 会改变结构”。

huangapple
  • 本文由 发表于 2023年6月30日 04:59:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76584581.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定