'Template docx disappears after rendering rmarkdown
I am knitting an Rmarkdown as a docx file and I have a template file for the formatting. Everything works fine with the rendering, however, once the process is completed, the template file disappears.
I have tried rendering the Rmd via the YAML and the rmarkdown::render function, but in both cases I get the same result.
Here are snippets of what I have tried:
#Render function
library(rmarkdown)
library(lubridate)
ruta = paste0(getwd(),'/scripts/random forest')
rmd.files = list.files(ruta, pattern ='.Rmd', full.names = T)
modelo_cr = render(rmd.files[1],
output_file = paste0('reporte_fwl_cr_',
format(ymd(Sys.Date()),'%d_%b_%Y'),
'.docx'),
output_dir = 'results/costa rica',
output_format = word_document(reference_docx = 'template.docx'),
envir = new.env())
#YAML Header
---
output:
word_document:
reference_docx: template.docx
---
Thanks in advance for any help you may provide.
Solution 1:[1]
Well, I figured it out. It turns out that the template document must be in the same folder as the rmarkdown that will be rendered. Otherwise, the template disappears. This works both for the instruction in the YAML of the rmarkdown and for the rmarkdown::render function in a separate r script.
I tried this with all my rmarkdowns and both methods, worked every time.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Carlos Aguilar |
