Knitr is Awesome!

January 19, 2012
By

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

I love TikZ in LaTeX and I use it exclusively when writing figures for my papers. I also use the tikzDevice package to convert all figures I create in R to TikZ code, so the font used in the text and figures is the same (and having your R figures in TikZ code makes them look slightly more… sophisticated :)). In some of my longer papers, and especially my thesis it has sometimes been a chore to insert all those figures and make them look right. I have tried to use Sweave to alleviate this, but the extra code needed to write the tex file with the TikZ code in it, and then input that file in the original tex document, and the figure formatting, made my Sweave files look very messy.

This is why the new knitr package from Yihui Xie is fantastic. If you have not tried out this package I urge you to do so as soon as possible! My single most favorite feature of this package is that it allows you to use the tikzDevice from within the package. Simply specify the output device as tikz in any chunk that contains a figure, and it will appear in the final document as a nicely formatted TikZ figure. This feature is enough to convert me, but the knitr package also has some nice customizability options, that I am still playing around with.

The only thing that annoys me in knitr is that the default backcround colour for code chunks is too obtrusive, I actually like Sweaves approach more, where the code is indented and typeset with a typewriter font. However this can also be changed in the package options.

So head over to the knitr homepage and play around with the package, it really is quite well done.

P.S: Here is a link to a nice make file, which does a good job of converting the Rnw file to a pdf. If you dont know make, have a look at this post by Jeromy Anglim.

To leave a comment for the author, please follow the link and comment on his blog: The PolStat R Feed.

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...

Comments are closed.