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

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

Converting Table to LaTeX and calling inline R Markdown

问题

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

  1. library(gt)
  2. library(gtsummary)
  3. # 过滤和未过滤数据集的表格比较。
  4. comp <- mtcars %>% select(mpg, cyl, disp)
  5. latex_code <- comp %>% tbl_summary(by = cyl) %>% as_gt() %>% as_latex()
  6. latex_code %>% as.character() %>% cat()

r latex_code

我得到了以下错误:

  1. ! Argument of \@iiminipage has an extra }.
  2. <inserted text>
  3. \par
  4. 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:

  1. ```{r}
  2. library(gt)
  3. library(gtsummary)
  4. #Table comparison of filtered and unfiltered dataset.
  5. comp &lt;- mtcars %&gt;% select(mpg, cyl, disp)
  6. latex_code &lt;- comp %&gt;% tbl_summary(by = cyl) %&gt;% as_gt() %&gt;% as_latex()
  7. latex_code %&gt;% as.character() %&gt;% cat()
  8. ```
  9. `r latex_code`

I get the following error:

  1. ! Argument of \@iiminipage has an extra }.
  2. &lt;inserted text&gt;
  3. \par
  4. 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:

确定