Saving your data (and getting them back)
There are several ways to save data. Some ways leave the data in a
form only understood by Splus.
Save as text
Typically data will come to you as a text file, with each line
containing fields separated by either "white space" or tabs.
(Example) Provided each line contains the same
number of fields, such date can be read into an Splus data.frame
object, using the
read.table() function.
If you wish to save such data, you can either: (i) save the original
text file, with the idea of using read.table() again at a later time;
or (ii) use dump() or data.dump(), as described below.
If you lose the original text file, you can also use the
write()
function on a data.frame from within Splus, in order to write it out
to a text file. Use this option if you want to read the data into
another program.
The dump() function
If you have objects in Splus that you wish to preserve for use at a
later time, and if you know that you will be using Splus to work with
the objects again, you can use the
dump()
function. This writes a set
of instructions to a text file, telling Splus how to recreate the
objects. (Example) You should not
run read.table() on a dump file; it would confuse Splus mightily. You
must use the
source()
function, which knows how to interpret the
commands in the dump file.
For example:
Suppose I have been working for a while, creating S objects, and that this is what I
have so far:
> objects()
[1] ".Last.fixed" ".Last.value" "last.dump"
[4] "ll" "mm" "test1"
[7] "test2" "test3" "values"
[10] "x" "xvalues" "y"
[13] "z"
Now I need coffee. I put my floppy disk into the slot (it becomes
drive A:) , then dump (everything):
> dump(objects(),"A:\\sept4")
[1] "A:\\sept4"
For the purposes of a test, I kill everything, then try to restore it
from my floppy disk.
> remove(objects()) # all gone:
> objects()
character(0)
> source("A:\\sept4") # Back again:
> objects()
[1] ".Last.fixed" ".Last.value" "last.dump"
[4] "ll" "mm" "test1"
[7] "test2" "test3" "values"
[10] "x" "xvalues" "y"
[13] "z"
The data.dump() function
We have found that dump() can be very slow with large data sets. Even
worse, the Stalab machines have been known to hang when source()'ing a
large dump file. The
data.dump()
function is much faster. It writes Splus objects to a text file
(Example),
which again can be interpreted only by Splus. To get the objects back
into Splus you use the
data.restore()