简体   繁体   中英

SWeave with non-R code chunks?

I often use Sweave to produce LaTeX documents where certain chunks are produced dynamically by executing R code. This works well - but is it also possible to have code chunks that are executed in different ways, eg by executing the code in the shell, or by running Perl, and so on? It would be helpful to be able to mix things up, so I could do things like run some shell commands to fetch some data, run some perl commands to pre-process it, and then run R commands to analyze it.

Of course I could use all R chunks and use system() as a poor-man's substitute, but that doesn't make for very pleasant reading in the document.

The new new thing (for multi-language, multi-format) docs may be dexy.it which for example these guys at opengamma.org use as the backend.

Ana , who is behind dexy, is also giving a lot of talks about it so also look at the dexy blog .

It's not directly related to Sweave, but org-babel , which is part of Emacs org-mode , allows to mix code chunks of different languages in one file, pass data from one chunk to another, execute them, and generate LaTeX or HTML export from the output.

You can find more informations about org-mode here :

http://www.orgmode.org/

And to see how org-babel works :

http://orgmode.org/worg/org-contrib/babel/

There is certainly no easy way to do this other than through either foreign language interfaces from R (maybe through inline if it's supported), or system() . For what it's worth, I would just use system() ; that should be easy enough.

You can see this previous question about having a Sweave equivalent for Python , where one of the respondents actually creates a separate interface. This can give you a sense what what it would take to embed other languages which may not already be supported. At a minimum, you have to do major hacking on the Sweave driver.

Do you know emacs" org-mode and, more specifically, Babel ? If you already know Emacs or are willing to switch to Emacs, then org-mode and Babel are the answer to your question(s).

For instance, I am currently working on a document which contains some shell-scripts, does computations with R and creates flow charts with dot (graphviz). Org-mode can export a variety of formats, eg LaTeX (that's what I use).

There is the StatWeave project which uses java rather than R to do the weaving, but will run multiple programs instead of just R. I don't know how hard it would be to get it to do Perl or other programs like that, but the homepage indicates that it already works with R, SAS, Stata, and others:

http://www.cs.uiowa.edu/~rlenth/StatWeave/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM