Site icon R-bloggers

Knitr is Awesome!

[This article was first published on The PolStat R Feed, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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 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 . 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 their blog: The PolStat R Feed.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.