3

Unable to use a modified Word template from Rstudio using Knit Word from Rstudio. Rstudio and required packages were installed and updated this week. 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. In all cases, knitting the RMD file uses the default formats and not the modified template stored as 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.

Community
  • 1
  • 1

2 Answers2

2

Pretty sure the indentation of the YAML header is the problem. 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.

Martin Schmelzer
  • 23,283
  • 6
  • 73
  • 98
0

Tried changing the reference thanks to Martin Schmelzer's comment and accidentally hit upon the solution.
Working YAML HEADER

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

FAILING YAML HEADERS.

---
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.

Martin Schmelzer
  • 23,283
  • 6
  • 73
  • 98