Message-ID: <Pine.LNX.4.64.0612180848080.2591@gannet.stats.ox.ac.uk>
Date: 2006-12-18T08:50:16Z
From: Brian Ripley
Subject: write() gotcha
In-Reply-To: <6ABA5A3B-B7C4-4278-A193-FCC72A4D809B@soc.soton.ac.uk>
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