process() is an R function which can be used to create a LaTeX document (usually but not necessarily in PDF format) from a simple text file. Any R commands are executed in the background and any numerical or graphical output is incorporated into the final document. It uses the R Sweave() utility.
It is assumed here that you have working versions of R and LaTeX, have a special dedicated process() folder and have successfully loaded process() into R. See the detailed instructions for setting up and loading process() if necessary.
The simplest example is as follows: consider a text file test consisting of just two lines:
Heading Hello WorldIf this is in the same directory that R was started in and all is working properly, then if you type
process(test)at the R prompt then a file test.pdf is opened in a PDF viewer. Note that the first line is a centred, large bold heading, the username is inserted as well as the date, and the second line is typeset as normal text.
Heading Here is some code: \code z <- rnorm(100) \end Here is a graph: \graph hist(z) \end Here is a final remark.Then typing
process(test2)opens a file test2.pdf in a PDF viewer; note that the blank line before the final remark ensures that the text after the graph starts on a new line.
<<(chunk parameters go here)>>= (R code goes here) @The utilities \code...\end and \graph...\end are equivalent to
<<>>= ... @and
<<fig=TRUE>>= ... @respectively, as the following example shows:
Heading Here is some code: <<>>= z <- rnorm(100) @ Here is a graph: <<fig=TRUE>>= hist(z) @ Here is a final remark.This gives identical output to the previous example. More sophisticated Sweave operations can be performed in this way, for example the scaling of graphics: supposing test3 is
Heading Here is some code: <<>>= z <- rnorm(100) @ Here is a graph: <<fig=TRUE,width=4,height=7>>= hist(z) @ Here is a final remark.then process(test3) gives test3.pdf with a bigger histogram.
Heading
Here is some code: we are going to generate some pseudo-random numbers
from the $N(\mu,\sigma^2)$ distribution with mean $\mu=0$
and variance $\sigma^2=1$.
\code
z <- rnorm(100)
\end
Here is a graph:
\graph
hist(z)
\end
Here is a displayed equation
$$\int_{-\infty}^\infty e^{-\frac{x^2}2}\,dx=\sqrt{2\pi}\,.$$
Then process(test4) gives test4.pdf.