【发布时间】:2020-01-31 21:25:11
【问题描述】:
在尝试通过从 R 脚本渲染 Rmd 文件来创建 PDF 时,我似乎在使用 kableExtra 时遇到了问题。我尝试按照以下说明操作没有成功:
R markdown compile error: https://github.com/rstudio/bookdown/issues/440 https://community.rstudio.com/t/rendering-both-pdf-and-html-is-only-possible-interactively-not-via-script/19520/3 https://github.com/haozhu233/kableExtra/issues/301
我将通过脚本访问包:
library(tidyverse)
library(knitr)
library(rmarkdown)
library(tinytex)
制作 Rmd 文件:
---
output: pdf_document
---
{r, comment = NA, echo = FALSE, message = FALSE, warning = FALSE}
tibble(x = 1, y = 2, z = 3) %>%
kable()
使用以下脚本渲染 Rmd 文件:
render('C:/Users/Rasmus/SO/Test.Rmd',
output_file = "Test.pdf",
output_format = 'pdf_document',
output_dir = 'C:/Users/Rasmus/SO')
这给了我一个带有表格的 PDF。但是,如果我开始与其他人一起运行library(kableExtra),然后应用渲染过程,我会得到一个 PDF:
x
y
z
1
2
3
运行library(kableExtra)后,我尝试了以下Rmd文件的渲染过程:
---
output: pdf_document
---
{r, comment = NA, echo = FALSE, message = FALSE, warning = FALSE}
tibble(x = 1, y = 2, z = 3) %>%
kable() %>%
kable_styling(latex_options = 'scale_down')
这会返回:
output file: Test.knit.md
Error: Functions that produce HTML output found in document targeting latex output.
Please change the output type of this document to HTML. Alternatively, you can allow
HTML output in non-HTML formats by adding this option to the YAML front-matter of
your rmarkdown file:
always_allow_html: true
Note however that the HTML output will not be visible in non-HTML formats.
是什么阻止我使用kableExtra?
【问题讨论】:
-
我在渲染时遇到了类似的问题。见stackoverflow.com/questions/62538467/…
标签: r pdf r-markdown kableextra