0

Objective

I'm creating a Word document using RMarkdown and I want to use a reference_docx file to apply some formatting. In addition, I'd like to use R code to specify the location of the reference_docx file inside the RMarkdown document's YAML header.

Here's a very simple example of what that would look like:

---
title: "RMD_Example"
output: 
  word_document:
    reference_docx: "`r print('my_styles_file.docx')`"
---

# Introduction
Four score and seven years ago...

This would be meant to achieve the same thing as the following YAML:

---
title: "RMD_Example"
output: 
  word_document:
    reference_docx: my_styles_file.docx
---

# Introduction
Four score and seven years ago...

The Problem

The version of this YAML without the R code works fine. However, when I try to render this document (my_rmd_file.rmd) with R code in the YAML, I get the following error message:

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m 
-RTS my_rmd_file.utf8.md 
--to docx 
--from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash+smart 
--output DELETEME.docx --highlight-style tango 
--reference-doc "`r print('my_styles_file.docx')`" 
output file: my_rmd_file.knit.md

pandoc.exe: `r print('my_styles_file.docx')`: 
BinaryFile: does not exist (No such file or directory)
Error: pandoc document conversion failed with error 1
Execution halted

My best guess of why this isn't working is that RMarkdown isn't running the R code inside the YAML header, and that's why you see the following line in the error message:

--reference-doc "`r print('my_styles_file.docx')`" 
bschneidr
  • 6,014
  • 1
  • 37
  • 52

0 Answers0