[Rd] undesirable rounding off due to 'read.table' (PR#8974)

Duncan Murdoch murdoch at stats.uwo.ca
Tue Jun 13 16:38:32 CEST 2006

overeem at knmi.nl wrote:
> Full_Name: Aart Overeem
> Version: 2.2.0
> OS: Linux
> Submission from: (NULL) (
> Construct a dataframe consisting of several variables by using 'data.frame' and
> 'cbind' and write it to a file with 'write.table'. The file consists of headers
> and values, such as 12.4283675334551 (so 13 numbers behind the decimal point).
> If this dataframe is read with 'read.table(filename, skip = 1)' or
> 'read.table(filename, header = TRUE') the values only have 7 numbers behind the
> decimal point, e.g. 12.42837. So, the reading rounds off the values. This is not
> mentioned in the manual. Although the values still have many numbers behind the
> decimal point, rounding off is, in my view, never desirable.
I don't see this.  Try the following script:

 > x <- data.frame(a=12.4283675334551)
 > x
1 12.42837
 > write.table(x,'test')
 > y <- read.table('test')
 > y
1 12.42837
 > y$a-x$a
[1] 0

If y$a had been rounded to 5 decimal places, then we would see a nonzero 
difference at the end.  I think you are being confused by the display, 
which only shows 5 decimal places, even though more are

maintained internally.  For example,

 > options(digits=20)
 > y
1 12.4283675334551

Please be careful about what you submit as a bug report.

Duncan Murdoch

More information about the R-devel mailing list