Learn R Programming

track (version 1.1.9)

track.plugin.lru: Plugins for cache policies in the track package.

Description

Plugins for cache policies in the track package specify what objects should be keep in memory at the end of each top level command.

Usage

track.plugin.lru(objs, inmem, envname)

Arguments

objs
: the full object summary dataframe. A subset of this data frame is returned by track.summary(); invoke track.summary(times=3, access=3, size=T, all=T) to get the full data frame. The names of the objects are in the rownames of the dataframe.
inmem
: a logical vector with length equal to the number of rows in objs. It will have value TRUE where the corresponding object is in memory, and FALSE otherwise.
envname
: a single string containing the name of the tracking environment, in a form like .

Value

A plugin function must return a logical vector the same length as inmem, with TRUE values where the corresponding objects should be kept in memory.

Details

track contains an experimental feature that allows users to supply their own plugin functions that specify cache rules. Currently, the plugin function can specify whether or not an object will be flushed from memory at the end of a top-level command.

track.plugin.lru() implements a simple least-recently-used discard policy. To use is, supply it to track.options():

  track.options(cacheKeepFun=track.plugin.lru, save=TRUE)

Here is another example of a very simple cache plugin function: this one keeps in memory variables whose names begin with the letter 'x'.

my.plugin <- function(objs, inmem, envname) {
    keep <- regexpr("^x", rownames(objs))>0
    # browser() # uncomment for debugging & development
    return(keep)
}

To use this plugin function, supply it to track.options():

  track.options(cacheKeepFun=my.plugin, save=TRUE)