I have been using delay() quite successfully to 'load on reference'
some large data files (earthquake catalogues). One minor difficulty I
have not been able to overcome is that upon first reference, the data
set is loaded into memory as expected, but also remains as a permanent
object in the user's environment, instead of appearing to be only in
the library from which it was loaded. For a simple example, I have a
data set test.x, which gets loaded from a library called test upon
first reference (not when the library is loaded). However the item
appears in the user's environment, and is saved with this upon exit.
But if the object is deleted, then it is still visible, without
(re-)appearing in the user's environment. See the sample below:
> library(test)
> test.x
[1] 123456.8> ls()
[1] "test.x"> rm(test.x)
> test.x
[1] 123456.8> ls()
character(0)>
I enclose a shar file of the library package test which exhibits the
behaviour above.
What I want to be able to do is to set up the library so that this
'permanent' assignment does not take place, so that the user of the
library does not have to explicitly delete objects before exiting.
[Some of these objects are 20-30 megabytes in size.]
Any hints? I suspect this might be a question for the developers :-).
A related issue is that when the object is large, and there is not
enough memory for it to be loaded, a subsequent reference to the object
results in the error:
Error: recursive default argument reference
even if enough permanent objects are removed to 'make room' for the
object to be loaded.
Ray Brownrigg
----
#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.1).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 2000-06-30 14:41 NZST by <ray at kore.mcs.vuw.ac.nz>.
# Source directory was `/usr/local/slocal/R/library'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 124 -rw-r--r-- test/DESCRIPTION
# 20 -rw-r--r-- test/INDEX
# 42 -rw-r--r-- test/R/zzz.R
# 52 -rw-r--r-- test/R/functions.R
# 107 -rw-r--r-- test/src/installtest.s
# 72 -rw-r--r-- test/src/Makefile
# 20 -rw-r--r-- test/data/00Index
#
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
shar_touch=touch
else
shar_touch=:
echo
echo 'WARNING: not restoring timestamps. Consider getting and'
echo "installing GNU \`touch', distributed in GNU File
Utilities..."
echo
fi
rm -f 1231235999 $$.touch
#
# ============= test/DESCRIPTION =============if test ! -d 'test'; then
echo 'x - creating directory test'
mkdir 'test'
fi
if test -f 'test/DESCRIPTION' && test X"$1" !=
X"-c"; then
echo 'x - skipping test/DESCRIPTION (file already exists)'
else
echo 'x - extracting test/DESCRIPTION (text)'
sed 's/^X//' << 'SHAR_EOF' >
'test/DESCRIPTION' &&
Package: test
Title: Test Functions
Version: 0.1-1
Author: Ray Brownrigg
Description: test functions
Depends:
License: GPL
SHAR_EOF
$shar_touch -am 06301015100 'test/DESCRIPTION' &&
chmod 0644 'test/DESCRIPTION' ||
echo 'restore of test/DESCRIPTION failed'
shar_count="`wc -c < 'test/DESCRIPTION'`"
test 124 -eq "$shar_count" ||
echo "test/DESCRIPTION: original size 124, current size
$shar_count"
fi
# ============= test/INDEX =============if test -f 'test/INDEX'
&& test X"$1" != X"-c"; then
echo 'x - skipping test/INDEX (file already exists)'
else
echo 'x - extracting test/INDEX (text)'
sed 's/^X//' << 'SHAR_EOF' > 'test/INDEX'
&&
text.x test delay()
SHAR_EOF
$shar_touch -am 06301015100 'test/INDEX' &&
chmod 0644 'test/INDEX' ||
echo 'restore of test/INDEX failed'
shar_count="`wc -c < 'test/INDEX'`"
test 20 -eq "$shar_count" ||
echo "test/INDEX: original size 20, current size $shar_count"
fi
# ============= test/R/zzz.R =============if test ! -d 'test/R'; then
echo 'x - creating directory test/R'
mkdir 'test/R'
fi
if test -f 'test/R/zzz.R' && test X"$1" !=
X"-c"; then
echo 'x - skipping test/R/zzz.R (file already exists)'
else
echo 'x - extracting test/R/zzz.R (text)'
sed 's/^X//' << 'SHAR_EOF' > 'test/R/zzz.R'
&&
X.First.lib <- function(lib, pkg) {
X
}
SHAR_EOF
$shar_touch -am 06301022100 'test/R/zzz.R' &&
chmod 0644 'test/R/zzz.R' ||
echo 'restore of test/R/zzz.R failed'
shar_count="`wc -c < 'test/R/zzz.R'`"
test 42 -eq "$shar_count" ||
echo "test/R/zzz.R: original size 42, current size $shar_count"
fi
# ============= test/R/functions.R =============if test -f
'test/R/functions.R' && test X"$1" != X"-c";
then
echo 'x - skipping test/R/functions.R (file already exists)'
else
echo 'x - extracting test/R/functions.R (text)'
sed 's/^X//' << 'SHAR_EOF' >
'test/R/functions.R' &&
test.x <- delay({data(test, package=test); test.x})
SHAR_EOF
$shar_touch -am 06301439100 'test/R/functions.R' &&
chmod 0644 'test/R/functions.R' ||
echo 'restore of test/R/functions.R failed'
shar_count="`wc -c < 'test/R/functions.R'`"
test 52 -eq "$shar_count" ||
echo "test/R/functions.R: original size 52, current size
$shar_count"
fi
# ============= test/src/installtest.s =============if test ! -d
'test/src'; then
echo 'x - creating directory test/src'
mkdir 'test/src'
fi
if test -f 'test/src/installtest.s' && test X"$1" !=
X"-c"; then
echo 'x - skipping test/src/installtest.s (file already exists)'
else
echo 'x - extracting test/src/installtest.s (text)'
sed 's/^X//' << 'SHAR_EOF' >
'test/src/installtest.s' &&
setuptest <- function ()
{
X test.x <- 123456.789
X save(test.x, file = "../data/test.rda")
}
X
setuptest()
SHAR_EOF
$shar_touch -am 06301045100 'test/src/installtest.s' &&
chmod 0644 'test/src/installtest.s' ||
echo 'restore of test/src/installtest.s failed'
shar_count="`wc -c < 'test/src/installtest.s'`"
test 107 -eq "$shar_count" ||
echo "test/src/installtest.s: original size 107, current size
$shar_count"
fi
# ============= test/src/Makefile =============if test -f
'test/src/Makefile' && test X"$1" != X"-c";
then
echo 'x - skipping test/src/Makefile (file already exists)'
else
echo 'x - extracting test/src/Makefile (text)'
sed 's/^X//' << 'SHAR_EOF' >
'test/src/Makefile' &&
dummy.so:
X echo 'source("installtest.s")' | R --no-save
X touch dummy.so
SHAR_EOF
$shar_touch -am 06301043100 'test/src/Makefile' &&
chmod 0644 'test/src/Makefile' ||
echo 'restore of test/src/Makefile failed'
shar_count="`wc -c < 'test/src/Makefile'`"
test 72 -eq "$shar_count" ||
echo "test/src/Makefile: original size 72, current size
$shar_count"
fi
# ============= test/data/00Index =============if test ! -d 'test/data';
then
echo 'x - creating directory test/data'
mkdir 'test/data'
fi
if test -f 'test/data/00Index' && test X"$1" !=
X"-c"; then
echo 'x - skipping test/data/00Index (file already exists)'
else
echo 'x - extracting test/data/00Index (text)'
sed 's/^X//' << 'SHAR_EOF' >
'test/data/00Index' &&
test.x test dataset
SHAR_EOF
$shar_touch -am 06301042100 'test/data/00Index' &&
chmod 0644 'test/data/00Index' ||
echo 'restore of test/data/00Index failed'
shar_count="`wc -c < 'test/data/00Index'`"
test 20 -eq "$shar_count" ||
echo "test/data/00Index: original size 20, current size
$shar_count"
fi
exit 0
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._