[R] [R-pkgs] New package lazyData submitted to CRAN

Bill Venables bill.venables at gmail.com
Sun Feb 24 02:22:35 CET 2013


I have submitted a tiny new package to CRAN, lazyData.  This has a single
function

requireData

which is designed as a drop-in replacement for base::require.  In addition
to doing the same job as base::require, it supplies a LazyData facility for
those packages which have data but do not provide LazyData.

The call is the same as for base::require but with an additional
side-effects.

After the package is attached, as necessary, a check is made if the package
supplies data objects.  If it does, and if it does NOT provide LazyData for
them, an additional entry is made on the search path, initially containing
'promises' to bring the data set into memory, at that point of the search
path, if and when they are needed.

Under these circumstances, a package 'pkg' would generate two entries on
the search path

package:pkg
datasets:pkg

If attaching a package causes others to be attached on the search path,
these are also checked for hidden data and any are exposed any in the same
way.
___

This has a number of advantages: data sets are initially visible on the
search path, they do not occupy memory until they are needed and when they
do silently enter memory it is on the search path and not cluttering up the
global environment as the use of data() would do by default.   (That is,
essentially the same advantages as if the package had provided LazyData in
the first place.)

A potential disadvantage is that is data sets in packages need to me
modified rather than simply used, the modified copy is held in the working
environment as well as the copy on the search path at the datasets:pkg
entry.   However using requireData() a second time on the package will
demote the visible copies of the data sets on the search path back to
promises and hence flush memory again.
__

To make the function itself automatically available within R sessions, one
way is to add a line to a ~/.Rprofile file.  e.g. from within R

cat('\nautoload("requireData", "lazyData")\n', file = "~/.Rprofile", append
= TRUE)

but this comes with the same caveats that using a ~/.Rprofile always carry.

-- 
Bill Venables,
Post-retirement Research Fellow,
CSIRO, Ecosciences Precinct,
41 Boggo Road,
Dutton Park, Qld, 4102
Australia.

	[[alternative HTML version deleted]]

_______________________________________________
R-packages mailing list
R-packages at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages



More information about the R-help mailing list