使用带有RStudio/rmarkdown/knitr的texreg软件包发布创建模型汇总表的问题 [英] Issue creating model summary table using package texreg with RStudio/rmarkdown/knitr

查看:315
本文介绍了使用带有RStudio/rmarkdown/knitr的texreg软件包发布创建模型汇总表的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将RStudio IDE(v 0.99.323)与rmarkdown一起使用,并试图通过knitr使用htmlreg生成模型表以生成MSWord输出.怀疑我错过了一些简单的事情.

I'm using the RStudio IDE (v 0.99.323) with rmarkdown and am attempting to produce model tables via knitr using htmlreg to produce MSWord output. Suspect I've missed something simple.

下面附加的rmarkdown块创建一个带有漂亮表的单独的Word文件'mytable.doc'.但是,当我在RStudio IDE中单击编织词"时,htmlreg(m)行在MSWord文档中生成html表代码.我在做什么错了?

The rmarkdown chunk appended below creates a separate word file 'mytable.doc' with a beautiful table. However, when I click 'Knit Word' in the RStudio IDE, the line htmlreg(m) generates html table code in the MSWord document. What am I doing wrong?

非常感谢! -戴尔

```{r, results='asis'}
library(MASS)
library(texreg)
data(menarche)
m <- glm(cbind(Menarche, Total-Menarche) ~ Age, family=binomial(logit), data=menarche)

htmlreg(m, file = "mytable.doc", caption="Age at Menarche", inline.css = TRUE, doctype = TRUE, html.tag = TRUE,                                               head.tag = TRUE, body.tag = TRUE, ci.force=TRUE, ci.test=NULL,bold=TRUE)

htmlreg(m)
```

推荐答案

能否请您尝试最新的texreg版本1.34.2(请参见.tar.gz文件帖子)?

Can you please try the latest texreg version 1.34.2 (see the .tar.gz file here or in this post)?

根据RStudio开发人员,问题在于他们切换到了较新版本的Pandoc,该版本不再适用于缩进的HTML代码.更准确地说,它会将以四个空格缩进的文本解释为代码块,如Markdown表示法那样.有关问题的说明,请参见此处.

According to the RStudio developers, the problem is that they switched to a newer version of Pandoc, which does not work with indented HTML code anymore. More precisely, it interprets text that was indented with four spaces as a code block, as in Markdown notation. See here for their problem description.

因此,在新的texreg版本中,htmlreg函数中有一个称为indentation = ""的新参数.默认情况下,它会关闭缩进.使用indentation = " "可以恢复以前的行为.

So in the new texreg version, there is a new argument called indentation = "" in the htmlreg function. It switches indentation off by default. Using indentation = " " restores the previous behavior.

编辑1 :还请确保使用参数center = FALSEstar.symbol = "\\*"在左侧对齐并正确显示重要恒星.星号需要转义,因为否则会将它们解释为Markdown语法的一部分:

Edit 1: Please also make sure to use arguments center = FALSE and star.symbol = "\\*" for alignment on the left and for displaying significance stars correctly. Asterisks need to be escaped because they are otherwise interpreted as part of the Markdown syntax:

```{r, results = 'asis'}
htmlreg(m, center = FALSE, star.symbol = "\\*")
```{r}

对于PDF笔记本(内部使用LaTeX),请使用texreg:

For PDF notebooks (which use LaTeX internally), use texreg:

```{r, results = 'asis'}
texreg(m, float.pos = "h")
```{r}

编辑2 :另请阅读htmlreg的帮助页面,尤其是描述htmlreg参数的部分.它们包含一些有关如何使文档与Markdown尽可能兼容的有用信息,RStudio,Pandoc和knitr使用它们来创建HTML文档.特别是当您不打算创建完整的HTML文档时,请使用参数inline.css = TRUEdoctype = FALSEhtml.tag = FALSEhead.tag = FALSEbody.tag = FALSE.

Edit 2: Also read the help page of htmlreg, especially the part where the arguments of htmlreg are described. They contain some useful information on how to make the documents as compatible as possible with Markdown, which is used by RStudio, Pandoc, and knitr to create HTML documents. In particular, use arguments inline.css = TRUE, doctype = FALSE, html.tag = FALSE, head.tag = FALSE, and body.tag = FALSE when you do not intend to create a full-fledged HTML document.

关于 MS Word :您在问题下方的评论中提到要创建HTML或Word文档. htmlreg函数用于创建HTML文件,而不是Word文件(正如该函数的名称所暗示的那样).但是,可以将这些HTML文件加载到MS Word中,因为Word能够解释HTML代码.但是,据我所知,knitr创建二进制Word文档,并且无法将HTML代码直接嵌入这些二进制Word文档中(但是我可能错了,因为我不知道knitr如何在内部创建Word文件).但是,您可以尝试创建HTML笔记本,将其保存到磁盘中,然后在MS Word中打开它们.

About MS Word: You mentioned in a comment below your question that you wanted to create either HTML or Word documents. The htmlreg function is intended to create HTML files, not Word files (as the name of the function implies). It is possible to load these HTML files in MS Word, though, because Word is able to interpret HTML code. However, knitr creates binary Word documents, and embedding HTML code directly in these binary Word documents is not possible, as far as I know (but I may be wrong because I don't know how knitr creates the Word files internally). You could, however, try to create HTML notebooks, save them to disk, and then open them in MS Word.

这篇关于使用带有RStudio/rmarkdown/knitr的texreg软件包发布创建模型汇总表的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆