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

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

save_kable as pdf changes structure

问题

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

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

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

编辑: 这是数据:

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

这是生成的PDF图像:

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

英文:

I created a table using

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

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

EDIT: This is the data

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

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

答案1

得分: 1

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

  1. df1 <- structure(list(TPR = c(0.934842767295597, 0.92922841571852),
  2. FPR = c(0.516589250165893, 0.525067529460655), ACC = c(0.867615330138182,
  3. 0.866211826128489), FAR = c(0.0881670095698295, 0.0834131044726853
  4. ), CSI = c(0.85734568558549, 0.856776377557092), BS = c(1.02523463957426,
  5. 1.01379194951716), HSS = c(0.444709565304963, 0.419220178831526
  6. ), tr = c(0.22, 0.25)), class = c("tbl_df", "tbl", "data.frame"
  7. ), row.names = c(NA, -2L))
  8. library(kableExtra)
  9. df1 |&gt;
  10. kable(format = "latex",
  11. digits = 2,
  12. caption="Statistical evaluation") |&gt;
  13. 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.

  1. df1 &lt;- structure(list(TPR = c(0.934842767295597, 0.92922841571852),
  2. FPR = c(0.516589250165893, 0.525067529460655), ACC = c(0.867615330138182,
  3. 0.866211826128489), FAR = c(0.0881670095698295, 0.0834131044726853
  4. ), CSI = c(0.85734568558549, 0.856776377557092), BS = c(1.02523463957426,
  5. 1.01379194951716), HSS = c(0.444709565304963, 0.419220178831526
  6. ), tr = c(0.22, 0.25)), class = c(&quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;
  7. ), row.names = c(NA, -2L))
  8. library(kableExtra)
  9. df1 |&gt;
  10. kable(format = &quot;latex&quot;,
  11. digits = 2,
  12. caption=&quot;Statistical evaluation&quot;) |&gt;
  13. 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:

确定