Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating reports in R

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.

like image 229
Marco M Avatar asked Jul 14 '12 18:07

Marco M


People also ask

How do I create an HTML report in R?

To produce an HTML report from an R script we can also use rmarkdown::render() on an R script file. This will create a report with slight differences to the default knit() output, one notable for HTML output is that render() will by default include inline base64 representations of fonts and JavaScript sources.

What is an RMarkdown report?

R Markdown is a widely-used tool for creating automated, reproducible, and share-worthy outputs, such as reports. It can generate static or interactive outputs, in Word, pdf, html, powerpoint, and other formats.

How do I publish a report in R?

Publish your R Markdown document to RStudio ConnectIn the Publish to Server window, confirm that your account is shown in the Publish To Account section and click Publish. You can monitor the status of the deployment in the RStudio IDE Deploy pane.

What tool can help them create this shareable report in R programming?

The knitr package, developed by Yihui Xie, is designed to generate reports within RStudio. It enables dynamic generation of multiple file formats from an RMarkdown file, including HTML and PDF documents. Knit report generation is now integrated into RStudio, and can be accessed using the GUI or console.


2 Answers

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.

like image 69
Greg Snow Avatar answered Oct 10 '22 08:10

Greg Snow


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.

like image 37
Dirk Eddelbuettel Avatar answered Oct 10 '22 08:10

Dirk Eddelbuettel