将模型对象的表添加到 officer/ReporteRs 的最佳实践

Best practice to add tables for model objects to officer/ReporteRs

flextable::body_add_flextable 可以将 flextable 插入到 officer 创建的 Word 文档中。包中包含的示例用于从数据框创建表格。我的问题是,从模型对象(例如 lm)创建表的最佳实践是什么?可以将模型对象转换为数据帧,例如,broom::tidy,但它支持有限类型的模型并且让它进行并排模型比较很麻烦,而像 texregstargazer 已经对此有很好的支持。有没有一种有效的方法可以将 texreg::htmlreg(或 texreg::screereg)输出转换为 flextable 并将其插入到 Word 文档中?或者更一般地说,有没有办法通过 officer 将 html 内容插入 Word 文档?

(我知道可以 create/customize 我自己的 flextables 中包含我想要的任何信息,但是重复 texreg 已经完成的工作包似乎是一种巨大的浪费做得很好。)谢谢!

出于演示目的,这就是我试图进入 Word 文档的内容:

library(texreg)
fit_m1 <- lm(mpg ~ wt, data=mtcars)
fit_m2 <- lm(mpg ~ wt + cyl, data=mtcars)
screenreg(list(fit_m1, fit_m2))
htmlreg(list(fit_m1, fit_m2))

这是一种解决方法,但据我所知包 huxtable has a function huxreg()。您可以使用 as_flextalbe() 转换 huxtable 或仅在 FlexTable() 中使用它。或者使用 pixiedust 你可以输出数据帧,这些可以在 vanilla.table(), FlexTable().

中使用

希望对您有所帮助。