简体   繁体   English

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

[英]Unable to use a modified word template in RStudio knitr

Unable to use a modified Word template from Rstudio using Knit Word from Rstudio. 无法使用Rstudio中的Knit Word从Rstudio中使用修改后的Word模板。 Rstudio and required packages were installed and updated this week. 本周安装并更新了Rstudio和所需的软件包。 Running OS X 10.10.5 and using Word 2011. Simplified testing to Yihui Xie's 113-externalization.rmd and 113-foo.R and have followed his Vimeo video https://vimeo.com/110804387 on this subject. 运行OS X 10.10.5并使用Word 2011.简化了对Yihui Xie的113-externalization.rmd和113-foo.R的测试,并在此主题上关注了他的Vimeo视频https://vimeo.com/110804387 In all cases, knitting the RMD file uses the default formats and not the modified template stored as template.docx. 在所有情况下,编织RMD文件使用默认格式,而不是存储为template.docx的修改模板。 I have tried putting copies in all locations in the project directory without success. 我已经尝试将副本放在项目目录中的所有位置,但没有成功。

#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)

Search found Changing word template for knitr in Rmarkdown , but that failed to locate the modified template at any location in the project directory. 搜索在Rmarkdown中更改knitr的单词模板 ,但无法在项目目录中的任何位置找到修改后的模板。

Pretty sure the indentation of the YAML header is the problem. 很确定YAML标头的缩进是问题所在。 Change it to: 将其更改为:

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

I also just found out for myself that it does not make a difference if you use reference_doc or reference_docx . 我还发现,如果你使用reference_docreference_docx ,它没有任何区别。

Tried changing the reference thanks to Martin Schmelzer's comment and accidentally hit upon the solution. 由于Martin Schmelzer的评论并且不小心碰到了解决方案,试图改变参考。
Working YAML HEADER 工作YAML HEADER

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

FAILING YAML HEADERS. 失败的YAML标题。

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

Putting everything in a single line also fails. 将所有内容放在一行中也会失败。 I haven't found the documentation yet but it appears that a CR and or an indent is needed between the various entries in the output line. 我还没有找到文档,但似乎输出行中的各个条目之间需要CR和/或缩进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM