Skip to content

format.info() versus format.default(): Comments please

2 messages · Duncan Murdoch, Brian Ripley

#
The format.info() function currently takes args (x, digits = NULL,
nsmall = 0), while format.default() takes many more:

function (x, trim = FALSE, digits = NULL, nsmall = 0, justify = c("left",
      "right", "centre", "none"), width = NULL, na.encode = TRUE,
      scientific = NA, big.mark = "", big.interval = 3, small.mark = "",
      small.interval = 5, decimal.mark = ".", zero.print = NULL,
      ...)

I think it would make sense for format.info to take at least the width,
scientific, big.*, small.*, and zero.print arguments, as these all
affect the output that format.info is calculating, i.e. the width,
decimal places, and scientific notation digits.  (It would probably be
sensible for it to take all possible format() arguments, but ignore some.)

For example, I was just writing some code to format durations as
HH:MM:SS.SSS (where the number of decimal places on the seconds was
chosen according to the values); here I wanted to tell format not
to use scientific notation, but I needed to use options(scipen=) to do
that because format.info doesn't take the scientific=FALSE argument.

Comments?

Duncan Murdoch
#
format.info() is used in no CRAN package (except in lists of known 
functions) and nowhere in R itself so I think you could do whatever you 
wanted by way of extending it.  However, I don't think it going to be 
easy, as apart from scientific those arguments are handled via 
postprocessing by prettyNum.

I would be tempted to replace format.info by a function that analysed the 
results.  The current description is wrong, of course:
[1] 6 0 0
[1] "123,456"

There are also assumptions that digits and the decimal mark are of width 
one, but those are I think benign.
On Mon, 1 May 2006, Duncan Murdoch wrote: