On Wed, Nov 12 2008, Eric Schulte wrote: > In the above example how would you/Sweave handle the case where there > are multiple R blocks in the same file? For example Sweave puts all variables defined in a document into the same environment. So assigning to a twice overwrites the first assignment. ,----[ tmp2.Rorg ] | #+BEGIN_R | a <- 3 | a | #+END_R | | - the value of a is \R{a} | - the value of a + 3 is \R{a + 3} | | #+BEGIN_R | a <- 8 | a | #+END_R | | - the value of a is \R{a} | - the value of a + 3 is \R{a + 3} `---- ,----[ tmp2.org ] | #+BEGIN_LaTeX | \begin{Schunk} | \begin{Sinput} | > a <- 3 | > a | \end{Sinput} | \begin{Soutput} | [1] 3 | \end{Soutput} | \end{Schunk} | #+END_LaTeX | | - the value of a is 3 | - the value of a + 3 is 6 | | #+BEGIN_LaTeX | \begin{Schunk} | \begin{Sinput} | > a <- 8 | > a | \end{Sinput} | \begin{Soutput} | [1] 8 | \end{Soutput} | \end{Schunk} | #+END_LaTeX | | - the value of a is 8 | - the value of a + 3 is 11 `---- > With that questions answered it should be relatively straightforward > to implement exporting as you described using only org-mode's block > processing, and letting ESS do the actual calculations all without any > dependence on Sweave. There is a Sweave.sty that handles formatting of the Schunk, Sinput, and Soutput environments. While you may not need to depend on Sweave for the preprocessing step, it would be nice if the formatted document at least had the option of having the same appearance as Sweave-processed files. Still, I suppose I could just add a #+LATEX_HEADER line for these files. > if you have examples of graphic creation, I'd be interested to see how > they work, and relatedly how difficult it would be to move that > functionality into org-mode. OK, here comes the first attempt. The additional feature demonstrated in this example is the inclusion of options to the Sweave preprocessor at the beginning of the block. In this case I've specified fig=TRUE to tell the preprocessor to generate image files for the plot commands contained in the block. By default, Sweave creates a .eps and a .pdf file for each block that contains a plotting or printing command and has the fig=TRUE argument, and then inserts an \includegraphics{} command in the output file. ,----[ tmp3.Rorg ] | * first figure | #+BEGIN_R fig=TRUE | x <- rnorm(100) | y <- rnorm(100) | | plot(x,y) | #+END_R `---- ,----[ tmp3.org ] | * first figure | #+BEGIN_LaTeX | \begin{Schunk} | \begin{Sinput} | > x <- rnorm(100) | > y <- rnorm(100) | > plot(x, y) | \end{Sinput} | \end{Schunk} | #+END_LaTeX | #+LaTeX: \includegraphics{tmp3-001} `---- ,----[ tmp3.tex ] | % Created 2008-11-12 Wed 23:46 | \documentclass[11pt,a4paper]{article} | \usepackage[utf8]{inputenc} | \usepackage[T1]{fontenc} | \usepackage{graphicx} | \usepackage{hyperref} | \usepackage{Sweave} | | \title{tmp3} | \author{Austin Frank} | \date{12 November 2008} | | \begin{document} | | \maketitle | | | \section*{first figure} | \label{sec-1} | | \begin{Schunk} | \begin{Sinput} | > x <- rnorm(100) | > y <- rnorm(100) | > plot(x, y) | \end{Sinput} | \end{Schunk} | \includegraphics{tmp3-001} | | \end{document} `---- And the pdf is attached.