[ESS] knitr

Rasmus rasmus at gmx.us
Sun Jun 3 20:08:30 CEST 2012


Kevin Wright <kw.stat at gmail.com> writes:

> I've used Sweave for many years, but have switched to knitr because I
> find knitr makes several things _much_ easier.  I added this to my
> .emacs:

I like Knitr a lot and have written several papers with it.  It makes
including graphs easy.  I use noweb syntax.

However, I don't know if the <<KEYWORDS>> have stabilized.  It seems
they change every so often.  This might be taken into consideration
before implementing Knitr support.  That is unless Yihui says the syntax
has stabilized.

Here's what I use.  Knitr makes the .tex files and latexmk runs pdflatex
and Biber the appropriate number of times:

(add-hook 'Rnw-mode-hook
          (lambda ()
            (add-to-list 'TeX-command-list
                         '("knitr" "/home/rasmus/bin/knitr %s.Rnw %s.tex && latexmk -pdf %s.tex"
                           TeX-run-command nil the:help "Run Knitr") t)

            (setq TeX-command-default "Knitr")))

With the /home/rasmus/bin/knitr shipped with Knitr, i.e.

$ cat ~/bin/knitr 
#!/usr/bin/env Rscript

local({
    p = commandArgs(TRUE)
    if (length(p) == 0L || '--help' %in% p) {
        message('usage:
    knit input [output] [--pdf]
    knit --help to print help messages')
        q()
    }

    library(knitr)
    knit_fun = if ('--pdf' %in% p) {
        p = setdiff(p, '--pdf')
        if (length(p) == 0L) stop('no input file provided')
        knit2pdf
    } else knit

    if (!file.exists(p[1]))
        stop("file '", p[1], "' does not exist!")

    knit_fun(p[1], if (length(p) < 2L) NULL else p[2])
})

–Rasmus

-- 
In theory, practice and theory are the same. In practice they are not



More information about the ESS-help mailing list