环顾四周寻找我的问题的答案,但我很困惑。
我正在尝试使用rmarkdown :: render在脚本中批量渲染一些pdf,但它一直给我这个错误:
! Use of \@array doesn't match its definition.
\new@ifnextchar ...served@d = #1\def \reserved@a {
#2}\def \reserved@b {#3}\f...
l.85 ...2in}|>{\raggedright\arraybackslash}p{4in}}
Error: Failed to compile C:/Users/cmykim/Desktop/stackoverflow/testfile.tex.
See testfile.log for more info.
In addition: Warning messages:
1: running command '"pdflatex" -halt-on-error -interaction=batchmode
"C:/Users/cmykim/Desktop/stackoverflow/testfile.tex"' had status 1
2: running command '"pdflatex" -halt-on-error -interaction=batchmode
"C:/Users/cmykim/Desktop/stackoverflow/testfile.tex"' had status 1
但是,当我运行.Rmd文件本身时,它会生成一个没有问题的PDF。
我创建了一个示例,它给出了以下错误:
rmarkdown文件:
---
output: pdf_document
---
```{r setup, include=FALSE}
## Packages
library(tidyverse)
library(knitr)
library(kableExtra)
library(tinytex)
dat <- data.frame(stringsAsFactors=FALSE,
id = c(1L, 2L, 3L),
name = c("bob", "sam", "jane"),
question1 = c("Lorem ipsum dolor sit amet", "consectetur adipiscing",
"Integer quis")
)
dat <- dat %>% slice(1) %>% gather("key", "value")
```
```{r echo=FALSE}
dat %>%
kable("latex", col.names = NULL) %>%
# making column 2 4 inches wide
column_spec(2, width = "4in") %>%
# making column 1 2 inches wide
column_spec(1, width = "2in")
r script:
library(rmarkdown)
rmarkdown::render(input =
"C:\\Users\\cmykim\\Desktop\\stackoverflow\\reproducible.Rmd",
output_format = "pdf_document",
output_file = "testfile.pdf",
output_dir = "C:\\Users\\cmykim\\Desktop\\stackoverflow")
我安装了tinytex,希望能解决它,但事实并非如此。
任何帮助将不胜感激!
答案 0 :(得分:1)
在我的机器上,我将以下内容添加到YAML命令中,它可以正常工作:
---
header-includes:
\usepackage{array}
output:
pdf_document
---