将表格转换为LaTeX并调用内联R Markdown

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

Converting Table to LaTeX and calling inline R Markdown

问题

我尝试在R Markdown中使用gtsummary,但它不直接支持。所以我将一个gtsummary表格转换成了LaTeX格式并存储在变量latex_code中。我的意图是内联调用它,但似乎不起作用。我的代码:

library(gt)
library(gtsummary)
# 过滤和未过滤数据集的表格比较。
comp <- mtcars %>% select(mpg, cyl, disp)
latex_code <- comp %>% tbl_summary(by = cyl) %>% as_gt() %>% as_latex()

latex_code %>% as.character() %>% cat()

r latex_code

我得到了以下错误:

! Argument of \@iiminipage has an extra }.
<inserted text> 
                \par 
l.281 \end{table}
英文:

I'm trying to use gtsummary with R Markdown but it doesn't support it directly. So I took a gtsummary table, converted it into LaTeX and stored it in a variable latex_code. The intent was to call it inline but it doesn't seem to work. My code:

```{r}
library(gt)
library(gtsummary)
#Table comparison of filtered and unfiltered dataset. 
comp &lt;- mtcars %&gt;% select(mpg, cyl, disp)
latex_code &lt;- comp %&gt;% tbl_summary(by = cyl) %&gt;% as_gt() %&gt;% as_latex()

latex_code %&gt;% as.character() %&gt;% cat()
```

`r latex_code`

I get the following error:

! Argument of \@iiminipage has an extra }.
&lt;inserted text&gt; 
                \par 
l.281 \end{table}

答案1

得分: 1

gtsummary有大量的打印选项供R Markdown和Quarto使用(参见:https://www.danieldsjoberg.com/gtsummary/articles/rmarkdown.html)。

根据您的设置(例如gt或flextable),已经选择了一些合理的打印引擎默认值,但您可以尝试该教程中列出的任何打印选项。

英文:

gtsummary has tons of printing options for R Markdown and Quarto (see: https://www.danieldsjoberg.com/gtsummary/articles/rmarkdown.html).

Some sensible print engine defaults are chosen based on your setup (e.g. gt or flextable), but you can try any of the print options listed in that vignette for R Markdown.

huangapple
  • 本文由 发表于 2023年6月1日 16:10:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76379887.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定