r - 无法使用 r 中的 {gtsummary} 包编织成 pdf
问题描述
我无法使用gtsummary包编织成 pdf。这是一个代表:
library(gtsummary)
reg <- lm(hp ~ cyl, mtcars)
tbl_regression(reg, intercept = TRUE)
此错误仅在我使用intercept = TRUE
参数时发生。如果我删除intercept
参数,我可以很好地编织成 pdf。
尝试编织到 pdf 后出现的错误消息:
output file: reprex.knit.md
! Undefined control sequence.
<argument> ...al \expandafter \let \cmrsideswitch
\@tempa \fi \fi
l.129 (Intercept)
& -51 & -102, -0.03 & 0.050 \\
Error: LaTeX failed to compile reprex.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See reprex.log for more info.
Execution halted
最后,我的sessionInfo()
:
R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] gtsummary_1.2.6
loaded via a namespace (and not attached):
[1] Rcpp_1.0.3 pillar_1.4.3 compiler_3.6.2 tools_3.6.2 digest_0.6.24 checkmate_2.0.0 evaluate_0.14
[8] lifecycle_0.1.0 tibble_2.1.3 nlme_3.1-142 gtable_0.3.0 lattice_0.20-38 pkgconfig_2.0.3 rlang_0.4.4
[15] rstudioapi_0.11 commonmark_1.7 yaml_2.2.1 xfun_0.12 dplyr_0.8.4 stringr_1.4.0 knitr_1.28
[22] sass_0.1.2.1 generics_0.0.2 vctrs_0.2.3 grid_3.6.2 tidyselect_1.0.0 glue_1.3.1 R6_2.4.1
[29] rmarkdown_2.1 tidyr_1.0.2 purrr_0.3.3 ggplot2_3.2.1 magrittr_1.5 backports_1.1.5 scales_1.1.0
[36] htmltools_0.4.0 assertthat_0.2.1 gt_0.1.0 colorspace_1.4-1 stringi_1.4.6 lazyeval_0.2.2 munsell_0.5.0
[43] broom_0.5.4 crayon_1.3.4
解决方案
我能够在我的机器上重新创建错误。gtsummary 默认使用 gt 包来打印表格。目前,gt 支持 HTML 输出,未来计划使用 LaTeX 和 RTF。虽然您可以为 R markdown 指定 PDF 和 RTF 输出(它通常可以工作并且看起来很棒!),但该功能尚未最终确定。
您还可以使用 {huxtable} 通过 LaTeX 在 R markdown 中从 gtsummary 输出表格。
library(gtsummary)
reg <- lm(hp ~ cyl, mtcars)
tbl_regression(reg, intercept = TRUE) %>%
as_hux_table()
希望这可以帮助!
推荐阅读
- s4sdk - S/4HANA 扩展 - 多租户
- android - Viewpager 内的多个 Recyclerview 问题
- c++ - 受保护的数据结构元素按值跨函数传递
- javascript - 如何避免 ajax PUT 的 400 (Bad Request)
- r - 如何更改笔记本 Rmarkdown 中的 dpi 内联代码输出
- apache-spark - spark中的dataframe.show()和dataframe.take()有什么区别?为了提高性能,我们需要增加什么?
- php - 在 Woocommerce 管理员、订单和电子邮件中显示自定义付款字段
- mongodb - 我需要将我的 mongo 集合转换为对象数组到字符串数组
- angular - Angular: [disabled]="isDisabled()" 是正确的方法吗?
- javascript - 列中包含“n”个单词的数据表过滤器