Skip to content
Prev 78775 / 398502 Next

Writing to a file with fixed precision

On Tue, 2005-10-11 at 08:42 +0100, Prof Brian Ripley wrote:
Indeed. Sorry, I was not clear in my use of words. I was thinking along
the lines of a single function call such as:

  write.fmt(x, file = "data.txt", ndigits = 14)

It would of course be easy enough to create such a wrapper using
existing functions.

I was aware of format(), but for some reason had in the back of my mind
that the use of 'nsmall' was not consistent in the decimal place output
based upon prior experience.

The result of which led me to use the vectorized formatC() to control
such output. I then shifted to using sprintf(), when in 2.1.0, it was
vectorized.

Using format() also adds the benefit of having methods for matrices,
etc., as opposed to sprintf().

Thanks,

Marc