2016-09-20 72 views
3

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

#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,但未能在项目目录中的任何位置找到修改的模板。

+0

在视频中他使用'reference_docx:'。这是否有所作为? –

+0

是的,我改为reference_docx:并收到一条失败消息。输入文本为 – user3838963

+1

对我来说,它可以使用'reference_docx:word-template.docx'工作。确保YAML标题中的缩进是正确的(再次检查视频)。 –

回答

2

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

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

我也只是发现了我自己,如果你使用reference_docreference_docx它不会有所作为。

+0

非常感谢。 '可以'找到任何文件,但它似乎是解决方案。 – user3838963

+0

该文档位于:http://rmarkdown.rstudio.com/word_document_format.html#style_reference –

0

感谢Martin Schmelzer的评论,并试图改变参考文献并意外触及解决方案。
工作YAML HEADER

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

失败YAML头。

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

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