无法在RStudio knitr中使用修改后的单词模板

时间:2016-09-20 15:39:40

标签: r ms-word rstudio knitr r-markdown

无法使用Rstudio中的Knit Word从Rstudio中使用修改过的Word模板。本周安装并更新了Rstudio和所需的软件包。运行OS X 10.10.5并使用Word 2011.对Yihui Xie的113-externalization.rmd和113-foo.R进行了简化测试,并在此主题上关注了他的Vimeo视频https://vimeo.com/110804387。在所有情况下,编织RMD文件使用默认格式,而不是存储为template.docx的修改模板。我已经尝试将副本放在项目目录中的所有位置,但没有成功。

#113-externalization.Rmd
---
title: "Untitled"
output:
     word_document: 
     reference_doc: "template.docx"
---

# Code Externalization

```{r cache=FALSE}
knitr::read_chunk('113-foo.R')
```

The following two chunks are from the external R script `113-foo.R`:

```{r test-a}
```
```{r test-b}
```
#code for 113-foo.R
# ---- test-a ----
1 + 1
x = rnorm(10)

# ---- test-b ----
mean(x)
sd(x)

搜索找到Changing word template for knitr in Rmarkdown,但未能在项目目录中的任何位置找到修改后的模板。

2 个答案:

答案 0 :(得分:2)

非常确定YAML标头的缩进是问题所在。将其更改为:

---
title: "Untitled"
output:
  word_document: 
    reference_docx: "template.docx"
---

我还发现,如果您使用reference_docreference_docx,这并没有什么不同。

答案 1 :(得分:0)

由于Martin Schmelzer的评论,我试图更改参考文献,并意外地找到了解决方案 工作YAML HEADER

---
title: "Untitled"
output:
     word_document:
      reference_doc: "template.docx"
---

失败的YAML HEADERS。

---
title: "Untitled"
output:
     word_document:
      reference_doc: "template.docx"
---

将所有内容放在一行中也会失败。我还没有找到文档,但似乎输出行中的各个条目之间需要CR和/或缩进。