Wednesday, April 11, 2012

Latex Allergy Cured by knitr

I have always known that at some point I would have to succumb to the power of Latex, but Latex has been uncharacteristically intimidating to me.  I finally found the remedy to my Latex allergy with the amazing and fantastic knitr package from Yihui Xie.  With very minimal effort, I ran my first experiment and now am extremely excited to incorporate it in production-quality performance reports (I plan to document the steps to get there in future posts).

For those starting from scratch on Windows, I think the easiest method to get up and running is to install LyX, which will also install MikTex.  If these are successfully installed, then you should be ready to experiment with knitr in R.

I will use knitr’s stich function, which is clearly not designed for the robust production use of knitr, but makes for a very easy first test.  stitch will open a very short script, apply a template, and generate a Sweave style .Rnw (can be changed).  knit2pdf converts the .Rnw file into a pdf, and with a couple lines of code you get a remarkable result.

 

 

R code from GIST (unbelievably only 7 lines):

2 comments:

  1. I'm glad that you find it useful. Thanks for sharing the example.

    ReplyDelete
  2. I get in the pdf several lines like the following. I am using Windows and Greek locale. Do you know of a solution?

    ## Warning message: conversion failure on 'ÎZÎsΡ 97' in 'mbcsToSbcs': dot substituted for
    ## Warning message: conversion failure on 'ÎZÎsΡ 97' in 'mbcsToSbcs': dot substituted for <99>
    ## Warning message: conversion failure on 'ÎZÎsΡ 97' in 'mbcsToSbcs': dot substituted for
    ## Warning message: conversion failure on 'ÎZÎsΡ 97' in 'mbcsToSbcs': dot substituted for
    ## Warning message: conversion failure on 'ÎZÎsΡ 97' in 'mbcsToSbcs': dot substituted for
    ## Warning message: conversion failure on 'ÎZÎsΡ 97' in 'mbcsToSbcs': dot substituted for <99>
    ## Warning message: conversion failure on 'ÎZÎsΡ 97' in 'mbcsToSbcs': dot substituted for
    ## Warning message: conversion failure on 'ÎZÎsΡ 97' in 'mbcsToSbcs': dot substituted for
    ## Warning message: conversion failure on 'ÎZΣÏEÎz 97' in 'mbcsToSbcs': dot substituted for
    ## Warning message: conversion failure on 'ÎZΣÏEÎz 97' in 'mbcsToSbcs': dot substituted for <99>

    ReplyDelete