cache {RbcBook1} | R Documentation

## cache an R expression to use the result without recomputation in later Sweave events

### Description

cache an R expression to use the result without recomputation in later Sweave events

### Usage

    cache(name, expr)

### Arguments

`name` | character variable
`expr` | R expression

### Details

If the object `tmp-[name].Rdata` does not exist, `expr` is evaluated and written to `tmp-[name].Rdata`. Otherwise, `tmp-[name].Rdata` is loaded and assigned to `[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.

### Value

The value of `expr`.

### Author(s)

Wolfgang Huber <w.huber@dkfz.heidelberg.de>

### Examples

    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)))

[Package RbcBook1 version 1.0.0 Index]