[Rd] truncation/rounding bug with write.csv

Gregory Michaelson greg at datarobot.com
Wed Mar 14 13:24:27 CET 2018

Hello, I have looked on https://www.r-project.org/bugs.html , but it seems
that this is the only way to do it.

The issue is that the precision used by write.csv is on consistant for big
files.  See the following code:

First I create a large dataframe filled with random uniform values.  Then I
write it to .csv and print out the first and last lines.

df = data.frame(replicate(100, runif(1000000, 0,1)))

write.csv(df, "temp.csv")
system('tail -n1 temp.csv')
system('head -n2 temp.csv')

If you run this, you will note that the precision for the first line is
different from the preision of the last line.  I'm not sure what is
Controlling this, but in the code that led me to this bug, I was only
getting 3 decimal Points by the end of the file.

if you use the write functionality in readr, then you get consistent

readr::write_csv(df, "temp2.csv")
system('tail -n1 temp2.csv')
system('head -n2 temp2.csv')

 I hope that this ishelpful.  If this is not the proper way to submit the
bug, please let me know.



	[[alternative HTML version deleted]]

More information about the R-devel mailing list