more on dput

Prof Brian D Ripley ripley@stats.ox.ac.uk
Fri, 12 Feb 1999 20:58:22 +0000 (GMT)


On Fri, 12 Feb 1999, Paul Gilbert wrote:

> I would like to write data so that I can re-read it and reproduce results,
> preferably in both R and Splus. In the past when I have done this my data has
> been relatively simple and I've just scan()ed it. Now I have a fairly
> complicated structure I would like to preserve and I've been trying to use dput
> and dget. Is there a better way?  If not, the following truncation by dput,
> which I mentioned yesterday, is causing me a fair amount of trouble. Suggestions
> on how to fix it would be appreciated.
> 
> Paul Gilbert
> _______
> 
> R:
> > dput (1/3, "zot")
> > (1/3) - dget("zot")
> [1] 3.333333e-08
> 
> Splus 3.3:
> > dput(1/3, "zot")
> > (1/3) - dget("zot")
> [1] 3.330669e-16
> 
> written by Splus, read in R:
> > (1/3) - dget("zot")
> [1] 3.330669e-16
> 
> so the problem seems pretty clearly to be in R's dput.

I find:

> dput(1/3)
0.3333333
> as.character(1/3)
[1] "0.333333333333333"
> options(digits=16)
> dput(1/3)
0.3333333333333333

so either use as.character or set digits to something large.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._