\HeaderA{cache}{cache an R expression to use the result without
recomputation in later
Sweave events}{cache}
\keyword{models}{cache}
\begin{Description}\relax
cache an R expression to use the result without
recomputation in later
Sweave events
\end{Description}
\begin{Usage}
\begin{verbatim}
cache(name, expr)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{name}] character variable
\item[\code{expr}] R expression
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
If the object \code{tmp-[name].Rdata} does not exist,
\code{expr} is evaluated and written to \code{tmp-[name].Rdata}.
Otherwise, \code{tmp-[name].Rdata} is loaded and assigned
to \code{[name]}.

Note that if a graph is produced as a side effect of
the cached command, it will not be produced when the
cached object is encountered in future weavings.
To avoid this problem, explicitly create the graphics
output so that it persists and can be reused on future
weavings.  In general this process should be avoided
by making all graphical activities explicit, not byproducts
of expensive calculations that are likely to be cached.
In other words, all expensive calculations for which visualizations
are of interest should return an object for which a plotting
method is defined.  The object calculation can be cached and
the plotting method can be applied to the cached object.
\end{Details}
\begin{Value}
The value of \code{expr}.
\end{Value}
\begin{Author}\relax
Wolfgang Huber <w.huber@dkfz.heidelberg.de>
\end{Author}
\begin{Examples}
\begin{ExampleCode}
library(graph)
unix.time(cache("bigran", randomGraph(paste("a", 1:100), 1:20, .3)))
dir()
unix.time(cache("bigran", randomGraph(paste("a", 1:100), 1:20, .3)))
\end{ExampleCode}
\end{Examples}

