Learn R Programming

SOAR (version 0.99-11)

SOAR-package: SOAR: Utility functions for memory management

Description

This suite of functions has two distinct purposes:
  • To provide an easy mechanism to store objects on the disc, releasing memory during the R session, but in such a way as to keep them visible on the search path and automatically loaded into memory if and when they are needed, and

  • To allow objects to be made automatically available to multiple R sessions, possibly for testing prior to including them in formal packages.

Arguments

Details

Package:
SOAR
Type:
Package
Version:
0.99-11
Date:
2013-12-12
License:
GPL-2 or GPL-3
The function Store is used to take objects from memory and store them as .RData files, usually in a sub-directory of the current working directory we call a stored object cache. The directory is automatically created if required. The search path is augmented to contain an entry that mirrors the stored object cache, in the sense that if an object in the cache is required in future it is loaded into memory by the same lazy loading mechanism as is used in packages.

An established stored object cache may be added to, or re-positioned on, the search path by the function Attach, and the function Objects (alias: Ls) may be used to display the objects currently held in a stored object cache.

Objects may be removed from the stored object cache using the function Remove.

Any of the functions Store, Objects or Remove will silently attach existing stored object caches to the search path as required.

Variants on the four basic functions with ``Data'' or ``Utils'' in their names, such as StoreUtils or ObjectsData differ from the corresponding basic version only in the way that their default argument values are defined. The intention is to make it possible either to add to a local stored object cache or to a central stored object cache for data or utulity functions in a simple way.

A function Search is also provided to show items on the search together with their lib.loc directories, as appropriate.

References

David E. Brahm, (2002) Delayed Data Packages, R News, 2, pp 11--12. (Contains a brief discussion of the antecedent package, g.data.)

Examples

Run this code
## change default cache, keeping any previous setting
oldLC <- Sys.getenv("R_LOCAL_CACHE", unset = ".R_Cache")
Sys.setenv(R_LOCAL_CACHE=".R_Test")

## generate some dummy data
dummy <- rnorm(100)
mn <- mean(dummy)
va <- var(dummy)

Attach()                            # may give warning

## store it in the stored object cache
Store(dummy, mn, va)
Search()

Attach(pos=3)                       # change to pos=3
Search()

Objects()
Remove(mn, va)
Objects()
Remove(Objects())                   # empty the cache

detach(".R_Test")                   # remove from search path
Sys.setenv(R_LOCAL_CACHE=oldLC)     # restore normal default

Run the code above in your browser using DataLab