2

I am using pander to create docx reports via Windows7, following the examples at http://rapporter.github.io/pander/#live-report-generation.

myReport <- Pandoc$new(author="Jerubaal",title="Plot Anything", format="docx")

I've tried the example

myReport$add(plot(1:10))

and that doesn't work on Windows, but does on Linux.

Previously I got plots appearing using brew files and <%=plot(1:10)=>, but I am trying out the Live Report Generation because that method seems most suited to me.

I've also tried saving a plot to file first and then creating an image link, which again work in Linux, but not in Windows:

myReport$add("![](plots/myplot.png)")

I want to include ggplot2 plots - the code works on its own in R but doesn't appear in the docx (although I do get a blank line).

R version 3.0.2 (2013-09-25) -- "Frisbee Sailing" pandoc.exe 1.12.2.1

What am I missing? Thanks.

Edit: I'm back home and this works on Ubuntu:

library(pander)
library(ggplot2)
setwd("/home/jerubaal/R/Projects/reports")
attach(movies)
m=movies[sample(nrow(movies), 1000),]
myReport=Pandoc$new(author="Jerubaal",title="Testing plots in reports",format="docx")
myReport$add.paragraph("There should be a plot after this")
p=ggplot(data=m, aes(x=rating,fill=mpaa)) + geom_density(alpha=0.25)
ggsave(filename=paste(getwd(),"plots/movies.png",sep="/"),plot=p,width=6,height=3)
myReport$add(paste("![](",paste(getwd(),"plots/movies.png",sep="/"),")",sep=""))
myReport$add.paragraph("There should be a plot before this")
myReport$export(tempfile())

Q: Would it cause a problem if the png took too long to create or save?

Jerubaal
  • 65
  • 1
  • 7
  • Hm, this seems to be some strange bug - could you please add more details (probably at https://github.com/Rapporter/pander/issues). I tried to reproduce this under Windows XP with R 3.0.2 and the most recent version of `pander` (installed from GH via `library(devtools);install_github('pander', 'rapporter')` without success. It works fine here (both with `base` and with `ggplot`). – daroczig Jan 27 '14 at 21:08
  • I think I could reproduce the bug, which seems to be a path issue on Windows. Please try to put the `ggplot` expression directly to `myReport$add` and call `myReport$export` without the `tempfile()` argument. – daroczig Jan 28 '14 at 12:12
  • 1
    Awesome! It works! I wrote up an issue on github yesterday, but then shut down my computer before submitting it... Thank you so much @daroczig – Jerubaal Jan 29 '14 at 10:13

0 Answers0