0

Using the older ReporteRs package, it looks like it was possible to specify a Word template with code like:

doc <- docx(template = "your template.docx")

Is it possible to specify a Word template using the newer officer package? It may be in the documentation but I don't see it. A workaround might be to read the file I want to use as a template, to delete all the content, and then to add new output to the empty file. I wouldn't want to try something like that though if it's possible just to specify a template.

Thanks.

Paul
  • 383
  • 4
  • 14
  • I'm not familiar with the package, but searching for the word "template" in the package docs shows this: https://davidgohel.github.io/officer/articles/word.html#replace-content Seems to be exactly what you're describing as a workaround – camille Mar 06 '19 at 19:03
  • Thanks. Helpful. If there is no way to specify a "true" template as appears to have been possible in ReporteRs, this likely is my solution. – Paul Mar 06 '19 at 20:56

1 Answers1

2

Yes; you can open a connection to a docx template with doc <- read_docx(*your template file name here*).

Paggles01
  • 81
  • 4
  • Thanks. Consistent with what I stated earlier. Possible to connect with a document that has the properties you want. If you don't delete the contents of that file though, you get the contents of your "template" plus anything you add after that. The workaround would be to read the file, issue a command that deletes the template content, and then to start building a document that has the contents you want. Or manually delete everything from the template first. Different from specifying a template in Rmarkdown. There you can specify the template and get it's attributes but not it's content. – Paul Mar 06 '19 at 19:57