[R] write() gotcha

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Dec 18 09:50:16 CET 2006


On Mon, 18 Dec 2006, Robin Hankin wrote:

> Hi
>
> I used write() the other day to save some results.

Why not save()?  It is the only way to preserve the results exactly.

> It seems that write() does not record the full precision of
> the objects being written:
>
>
> > write(pi,file="~/f",ncolumns=1)
> > pi.saved <- scan("~/f")
> Read 1 item
> > dput(pi)
> 3.14159265358979
> > dput(pi.saved)
> 3.141593
> > pi-pi.saved
> [1] -3.464102e-07
> >
>
>
> This difficulty was particularly difficult to find because pi.saved
> *looks*
> the same as pi.
>
>
>
> What's going on here?

See ?cat, for which write is a wrapper.

-- 
Brian D. Ripley,                  ripley at 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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list