As much as we data scientists would like to work solely in R, there inevitably comes the time when our managers or customers want to see the fruits of our labours as a Word document or PowerPoint presentation. And not just any old document: it needs to be in the official corporate template, and will no doubt go through a series of back-and-forth revisions — marked up directly in the document — before it's considered final.
R has several options for generating Word and PowerPoint documents, notably RMarkdown and Slidify. But in both these cases, R is in the driver's seat, and if you want to make any changes to the document that will persist through changes to the R code, you'll need to make those changes with R. And as Aimee Gott from Mango points out, that doesn't work so well if the document will go through a review cycle with non-R users. (It's also quite tricky to use a corporate template with these solutions.)
That's where ReporteRs (created by David Gohel) comes in. While you can use ReporteRs to create complete documents and presentations programatically, one of the most useful features is to be able to insert R output (numbers, tables, and charts) into an existing document. This lets you use Word or Powerpoint as usual to style the document and build the narrative, and use R to insert the scientific results in the appropriate places.
For Word documents, simply place a named bookmark in the document where you'd like output from R to go. Then, you'll use that document and bookmark name in a call to addParagraph (to insert text, say a P-value or other result) or addImage (to insert a static PNG or JPG image). You can even use addPlot, to insert an R graphic that can be edited directly within the Word or Powerpoint file using the Drawing toolba: vary useful for pre-publication annotations, although such changes will be overwritten next time you generate the document. For tabular output like data frames, use the addFlexTable function to insert a table, which formats it nicely and gives lots of options for layout like merging cells and coloring rows and columns.
For Powerpoint presentations, first start with a PowerPoint presentation in your chosen template, and create blank slides where you'd like to insert R output. You can then replace those slides by indicating the slide number in the addSlide function. While you can only insert complete slides, ReporteRs gives you plenty of flexibility in the layout of the slides.
ReporteRs is an open source pacakge available for download on CRAN. For more details on ReporteRs and how to use it, check out its homepage at the link below.
David Gohel: ReporteRs