[R] dput and dget

Duncan Murdoch dmurdoch at pair.com
Thu Jul 15 20:57:35 CEST 2004

On Thu, 15 Jul 2004 14:22:12 -0400, "Mike Prager"
<Mike.Prager at noaa.gov> wrote :

>I am seeking advice about dput() and dget().
>We are using the ascii format supported by these functions as a way to 
>write data from other programs that can be read into R easily.  We are able 
>to save complicated results (in the form of an R list) to a single file 
>that can be read trivially into R or S-Plus.
>My question is whether that format can be considered a safe one for 
>medium-term (say 10 years) data storage. Assuming R is still used then 
>(which I suppose will be true), will "dget" work with old files?

I don't think dput alone is a very safe data storage strategy, but it
depends on what sorts of things you are storing.  For numerical or
character data in lists and data frames, it's probably perfectly safe.
For more complicated things (e.g. results of an analysis), it may not
be.  I'd recommend saving both as a dump and in a binary image.

The problem is that dput() in 1.9.x does not do a very complete job of
deparsing, and there are many objects for which dput followed by dget
changes the object. (Version 2 will be a tiny bit better by default,
and will have an option to be reasonably good, but there are still
some exotic objects which can't be dumped at all.  dump() will by
default do a better job.)

Assuming you've got a relatively simple object which can be dumped
correctly now, there might be changes to the syntax that mean dget
won't work.  Recent changes like that include the move of "_" from
being an assignment operator to being legal in object names.  There
are some aspects of R syntax that are still described as experimental
("::", ":::" come to mind); those might not be supported 10 years from

For more complicated objects, I'd guess that binary images saved by
save() are safer.  Whenever the binary image format changes, there
will be an effort to make sure older images can still be read.  But
it's likely that only R is going to be able to read binary images, and
10 years from now you might be using some other program:  so you want
the dump as well.

Duncan Murdoch

More information about the R-help mailing list