[Rd] obscure bug in format.default?

Tony Plate tplate at acm.org
Tue Jul 25 19:25:02 CEST 2006


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.

-- Tony Plate

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

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



More information about the R-devel mailing list