2

Using knitr to create Word documents from Rmarkdown files I have had no trouble using the YAML 'reference_docx' argument specifying a relative path, and have successfully use inline R in the 'date' argument, but I get an error if I try to use inline R in the reference_docx argument. I want to incorporate my reference document into the /inst folder in a personal package so that if I make any changes to the template all of my projects can be easily updated.

This works:

---
title: "My title"
author: "My name"
date: '`r lubridate::today()`'
output:
  word_document:
    reference_docx: "../Styles/Reference_Document.docx"
---

But this does not:

---
title: "My title"
author: "My name"
date: '`r lubridate::today()`'
output:
  word_document:
    reference_docx: '`r system.file("Styles", "Reference_Document.docx", package = "mypackage")`'
---

I also tried using file.path(.libPaths[1], "mypackage", "Styles", "Reference_Document.docx") with no luck. I know the file exists because if I write out the full path then the knit will go fine.

Here is the error I get using the above example:

pandoc.exe: `r system.file("Styles", "Reference_Document.docx", package = "mypackage")`: openBinaryFile: invalid argument (Invalid argument)

Am I just running into a problem with how certain YAML arguments are passed to pandoc? And is there a workaround to use your own reference documents or templates in a package?

jpshanno
  • 261
  • 2
  • 7

0 Answers0