Creating beautiful reports from R with knitr

August 21, 2012
By

(This article was first published on Revolutions, and kindly contributed to R-bloggers)

People use the R language every day to create the elements of reports: tables, charts, analyses, and forecasts. But assembling all of that information into a print-ready document laid out with text can a hassle. You can cut-and-paste all of the elements into Word, but then what do you do when the data file gets updated at the last minute? (Answer: you have to re-run all the R code and go through the whole cut-and-paste process again. What a pain.) An alternative is to Sweave, but that requires having a working TeX installation, and learning how to use LaTeX.

Now there's an easier-way: Yihui Xie's knitr package. It's a similar to Sweave in that it automates the process of combining text with images, data and code generated by R, but it's easier to learn and use because you structure the document with MarkDown instead of LaTeX.

RStudio has great knitr support and the ability to publish generated documents to the cloud for sharing. Take a look at the RStudio RPubs site (and also here) for some stunning examples of documents created with knitr, like the report on integrating R and Google visualizations excerpted below.

R Google Maps
For a primer on getting started with knitr and Markdown, see the tutorial from Jeromy Anglim linked below.

Jeromy Anglim's Blog: Psychology and Statistics: Getting Started with R Markdown, knitr, and Rstudio 0.96

To leave a comment for the author, please follow the link and comment on his blog: Revolutions.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: ,

Comments are closed.