Section 9 RMarkdown to Word

RMarkdown can be used to generate Word documents. This should be thought of as a one-way operation. That is to say, when a team works on a manuscript using Word, the typical work flow is that the lead author creates the first draft. Other authors make changes to the document using tracked changes. When the manuscript circulates over all authors, the lead author decides which changes to accept and which to reject, resulting in a new version. The process continues until the group of authors agrees that the manuscript is ready for publication.

RMarkdown can be used to generate the first draft, but there is no automated way of feeding the changes back into RMarkdown source. Nevertheless, generating the initial draft using RMarkdown can help with standardization of the formatting.

To use Word output, first make a minimal RMarkdown document with Word output.

Save the Rmd file and knit to to Word.

The output document will have the elements from the Rmd file.

The important part of this is that the Word document will have a number of styles. Make any changes to the styles or margins. This will become the template for the output containing the actual scientific content. Do not add, remove, or rename any styles in this document! Save a copy of the document with any stylistic changes.

For example, here are some changes to the header styles:

Which is then saved as a template:

In the head matter of the Rmd file with your scientific content, this construction, in which you specify the pathname to the template document.

    reference_docx: "template.docx"

When the Rmd file is rendered to a Word document, the stylistic changes will be applied to the output. For example, just changing the head matter of the previous document and re-rendering shows that the heading styles were applied as defined.

Although this overall functionality is somewhat limited, if you do have some Rmd code that generates some scientific content, and you want to output to a Word document with predefined formats, this will save you some busy work of reformatting.