0

I am creating a complex RMarkdown document that includes some charts made in ggplot2. I run the following code:

rmarkdown::render(input="U:/John/R/aa_app/output/template.Rmd")

This creates a Word document called "template.docx" with no problem.

However, I need to be able to specify a different file name and location for this document. So I run:

rmarkdown::render(input="U:/John/R/aa_app/output/template.Rmd",output_file="U:/John/R/aa_app/output/test.docx")

or

rmarkdown::render(input="U:/John/R/aa_app/output/template.Rmd",output_file="U:/John/R/aa_app/output/temp/test.docx")

In both cases, a Word document is created called "test.docx" but the charts are missing from the file. I get a series of error messages:

"C:/Program Files/RStudio/bin/pandoc/pandoc" template.utf8.md --to docx --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures
--output U:/John/R/aa_app/output/test.docx --highlight-style tango   
pandoc.exe: Could not find image `U:/John/R/aa_app/output/test_files/figure-docx/unnamed-chunk-3-1.png', skipping...  
pandoc.exe: Could not find image `U:/John/R/aa_app/output/test_files/figure-docx/unnamed-chunk-3-2.png', skipping...  
pandoc.exe: Could not find image `U:/John/R/aa_app/output/test_files/figure-docx/unnamed-chunk-4-1.png', skipping...  
pandoc.exe: Could not find image `U:/John/R/aa_app/output/test_files/figure-docx/unnamed-chunk-7-1.png', skipping...  
pandoc.exe: Could not find image `U:/John/R/aa_app/output/test_files/figure-docx/unnamed-chunk-8-1.png', skipping...  
pandoc.exe: Could not find image `U:/John/R/aa_app/output/test_files/figure-docx/unnamed-chunk-8-2.png', skipping...  
pandoc.exe: Could not find image `U:/John/R/aa_app/output/test_files/figure-docx/unnamed-chunk-8-3.png', skipping...  
pandoc.exe: Could not find image `U:/John/R/aa_app/output/test_files/figure-docx/unnamed-chunk-8-4.png', skipping...

Does anyone know what is going wrong?

UPDATE: Here is a reproducible example.

Code for Repro.Rmd:

---
title: "Repro"
author: "John Butters"
date: "Tuesday, April 28, 2015"
output: word_document
---


```{r, echo=FALSE}
plot(cars)
```

If I run the following code, a document is produced called "Repro.docx" that includes a plot of the "cars" dataset.

rmarkdown::render(input="U:/John/R/Repro.Rmd")

However, if I run the following code, a document is produced called "aaargh.docx" that does not include the plot, and I get the same pandoc error as above.

rmarkdown::render(input="U:/John/R/Repro.Rmd",output_file="U:/John/R/aaargh.docx")

"C:/Program Files/RStudio/bin/pandoc/pandoc" Repro.utf8.md --to docx --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output U:/John/R/aaargh.docx --highlight-style tango 
pandoc.exe: Could not find image `U:/John/R/aaargh_files/figure-docx/unnamed-chunk-1-1.png', skipping...
user33102
  • 323
  • 1
  • 2
  • 10
  • Any chance you could post a small [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) that generates the error you're getting? Are these charts created by R code that runs in the rmarkdown document or are they created separately and then the chart files are included by reference in the rmarkdown document? – eipi10 Apr 27 '15 at 15:33
  • Thanks for having a look. I have updated the question as you asked. The charts are created with code that runs in the rmarkdown document. – user33102 Apr 28 '15 at 13:36

1 Answers1

2

Got it. You can't give the output_file argument a full file path. There is also an output_dir argument that also will not take a full file path.

So, this works:

rmarkdown::render(input="U:/John/R/Repro.Rmd",output_file="aaargh.docx")

And this works too, as long as "Temp" is a sub-folder of "R".

rmarkdown::render(input="U:/John/R/Repro.Rmd",output_file="aaargh.docx",output_dir="Temp")
user33102
  • 323
  • 1
  • 2
  • 10