9

I've posted a similar question on Rstudio but I thought it would be useful to also ask stack users.

My question is basically this: how do you create documents with embedded R graphics that others can easily comment on?

In the past few months I've been wondering how to circulate R analysis within my company quickly without having to paste lots of plots and tables from R. I'm not interesting in embedding R code, but I do want to be able to customise where my plots go and write text around it (title, headings and paragraphs) from R. The package R2wd has huge potential but Rstudio is making the whole production of high quality documents in HTML, pdf and Latex much more intuitive. These formats are generally much more flexible, look better, and take full advantage of R's capabilities.

There are functions generally (but not necessarily correctly) associated with Word which make me (and again I may be wrong) not likely to switch to these other formats. Once the analysis is finished it is then uploaded on a common drive or circulated electronically, and then colleagues/supervisors/ can:

  1. review the document with Track changes (i.e. edit the text and then leave you the option to accept changes or not), and
  2. Comment on sections of the text (comments).

These two functions are absolutely crucial when publishing reports on the go (especially new types of analyses which have not been reviewed before), and I was wondering how you'd go about doing this in the formats currently supported by Rstudio (e.g. HTML, latex, pdf), or just how you generally deal with these issues . I'd love to switch to better formats like pdf but I don't know whether it would mean losing the two functions above.

Marco M
  • 623
  • 1
  • 8
  • 15
  • 1
    my 2 cents here: http://yihui.name/en/2012/03/a-really-fast-statistics-journal/ we are working on an example this summer, and hopefully in August you can see how you can write reports with knitr, track changes with GIT, collaborate with pull requests and comment on Github or disqus. – Yihui Xie Jul 14 '12 at 20:37

4 Answers4

5

In conjunction with the tools that you have discussed (rstudio and sweave/knitr) you might want to look at the pandoc program which will convert from the formats created by those tools into other tools including word .docx files (and others). So one option would be to create a basic template file in R or Rstudio and use the built in tools to work with and view it while creating it. Then when you are ready to share the document (with embedded graphs, output, etc.) you can convert to a .docx file and colaboraters can comment and track changes.

Other options would be to use R2wd (as mentioned in the question, but note that it uses non-free tools) or R2HTML or rtf packages to create those types of files which can be read in using ms word as well.

Greg Snow
  • 48,497
  • 6
  • 83
  • 110
  • How do you go back from Word to pandoc? Still seems like a one-way street to me. – Dirk Eddelbuettel Jul 16 '12 at 03:26
  • @DirkEddelbuettel, It is a bit of a one-way street, pandoc just translates between different formats. It does not translate from .docx files, but can translate from .html files (which could be saved from MSWord, but I have no idea what that would do with tracked changes or comments). It would not traslate back to the original knitr or sweave source. I agree that it would be best to do all the collaboration on the original template, but if some of the collaborators will only use Word, then this approach is a better start than copy/paste from excel. – Greg Snow Jul 16 '12 at 16:26
3

Have a look at Sweave (in base R) and the knitr ---and everything in the CRAN Task View on Reproducible Research which focusses on the very same topic.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Dirk, I think the OP's question is more about how one can create documents with embedded R graphics that one can easily comment on, rather than reproducible research. In the question, the OP states that he is familiar with knitr, but the problem is that PDF documents doesn't have easy "track changes" facilities. And the average corporate employee will not be able to use either EMACs or LaTEX, sadly. – Andrie Jul 14 '12 at 18:21
  • 5
    Just because someone "likes Word and tracking changes" does not make the R ecosystem have it. On our side, tracking changes means use a revision control system, and text will either be latex or markdown. Such is life. – Dirk Eddelbuettel Jul 14 '12 at 18:24
  • Thank you both. I've edited the question so that it goes straight to the point. – Marco M Jul 14 '12 at 18:32
2

Maybe you can import the knitr'ed HTML into Google Docs. There you have not only track changes but real time editing. I did not try this, though.

Karsten W.
  • 17,826
  • 11
  • 69
  • 103
  • Yes. I was able to use RStudio with Knitr to save an html output to google drive. From there I was able to open it but it had all the html tags and was extremely unfriendly to my non-coder eyes. I was then able to move it to regular google docs by clicking on file>open with>google documents. It was then a Google Doc which in my opinion is the best way for a group to collaborate on a document. The Google Docs did not look as nice as the html. I will explore further. – Farrel Oct 17 '12 at 15:15
1

Here is my thought about your question. Regarding writing a reproducible report (or data analysis), as Dirk has recommended, I would recommend using knitr or Sweave (I personally like knitr more). In the company I work, I write all my reports in a reproducible format so that it enables people to reproduce my research as well as helping me to easily change some parameters {in my case dosage of using our product} an getting a new report in just a second.

Regarding the editing and proofreading part, you can use http://www.mendeley.com/. I do have a private group on Mendeley with my team and I share my reports with them and they can easily comment on the report. We can also share documents with each other. It's quite useful to me.

Sam
  • 4,357
  • 6
  • 36
  • 60