2016-09-20 91 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和/或縮進。

相關問題