R Stargazer 错误 - 如何在使用 add.lines 参数时导出为 .html?

R Stargazer Error - how to export as .html when add.lines argument is used?

如何在 R 中使用 add.lines 参数时将 stargazer 结果 table 输出为 .html

我目前的做法是:

fem <- plm(model, data =pdata, effect = "twoways",model="within")

rob_se      <- sqrt(diag(vcovHC(fem, type = "HC1", cluster = "group")))                    
stargazer(fem,
          align=TRUE,
          type = "html",
          se = list(rob_se),
          out = "Test.html")

效果很好。然而,当使用函数的 add.line 参数时,例如

r2 <- 0.4
stargazer(fem, align=TRUE,
                          type = "html",
                          se = list(rob_se),
                          add.lines = list(c("$R^2$", r2)),
                          out = "Test.html")

我收到以下错误消息

Error in if (nchar(text.matrix[r, c]) > max.length[real.c]) { : 
  missing value where TRUE/FALSE needed

在这里,type = .html 参数提出了问题,因为我可以 运行 没有它的函数。不幸的是,结果随后被格式化为 R 中的字符。

将代码与 $R^2$ 一起使用会给出错误:

stargazer(fit1_robust, fit2_robust, type = "html", 
          add.lines = list(c("$R^2$", fit1_r2, fit2_r2)),
          out = "path/nameofthetable.html")

Error in if (nchar(text.matrix[r, c]) > max.length[real.c]) { : 
  missing value where TRUE/FALSE needed

改成R2解决问题:

stargazer(fit1_robust, fit2_robust, type = "html", 
          add.lines = list(c("R2", fit1_r2, fit2_r2)),
          out = "path/nameofthetable.html")