[R] options("digits") and print.default()

From: Ulrich Keller <ulrich.keller_at_emacs.lu>
Date: Mon 15 Jan 2007 - 16:14:20 GMT

Hello everyone,

I use latex() (Hmisc) for report generation and thus have been affected by the problem with rounding decimals described, for example, in this post:


In short, numbers often are printed with 15 or so decimals even if there far less significant digits. The problem has been confirmed by Frank Harrell and Thomas Dupont according to this post:


But it has still not been fixed. Rather than changing all my reports I decided I'd look at format.df() in Hmisc myself and try to fix the problem there. I found that the problem is not in Hmisc at all, but in R itself:

> print(1.001)

[1] 1.001
> options(digits=16) #format.df does this
> print(1.001)

[1] 1.001000000000000
> print(round(1.001, 3)) #rounding does not help
[1] 1.001000000000000

This does not seem to be the behaviour described in the documentation, which says:

"The same number of decimal places is used throughout a vector,[sic!] This means that digits specifies the minimum number of significant digits to be used, and that at least one entry will be encoded with that minimum number. However, if all the encoded elements then have trailing zeroes, the number of decimal places is reduced until at least one element has a non-zero final digit."

If print.default() exhibited the behaviour desribed in the docs, format.df() and thus latex() would work as advertised, I think. I would have written a bug report instead of posting here, but the fact (?) that Frank and Thomas have confirmed the bug seems to indicate that the problem does indeed lie with Hmisc. Am I misunderstanding something here?

I use R version 2.4.1 Patched (2007-01-13 r40470) on Windows.


R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue Jan 16 03:14:01 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 15 Jan 2007 - 18:30:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.