[Rd] obscure bug in format.default?

From: Tony Plate <tplate_at_acm.org>
Date: Tue 25 Jul 2006 - 17:25:02 GMT


Output from format.default sometimes has whitespace around it when using big.mark="," and trim=TRUE. E.g.:

> # works ok as long as big.mark is not actually used:
> format(c(-1,1,10,999), big.mark=",", trim=TRUE)

[1] "-1" "1" "10" "999"
> # but if big.mark is used, output is justified and not trimmed:
> format(c(-1,1,10,999,1e6), big.mark=",", trim=TRUE)

[1] " -1" " 1" " 10" " 999" "1,000,000"
>

I am unable to come up with any interpretation of the documentation for format.default under which this output could be considered correct, so I suspect this behavior should be classified as a bug.

The last call to 'prettyNum' in format.default has the argument

   preserve.width = "common"

If this is changed to

   preserve.width = if (trim) "individual" else "common"

then output is formatted correctly in the case above.

> sessionInfo()

Version 2.3.1 (2006-06-01)
i386-pc-mingw32

attached base packages:
[1] "methods" "stats" "graphics" "grDevices" "utils" "datasets" [7] "base"
>



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed Jul 26 03:26:50 2006

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 Tue 25 Jul 2006 - 20:40:29 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.