Duncan Murdoch
2006-May-01 16:23 UTC
[Rd] format.info() versus format.default(): Comments please
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
Prof Brian Ripley
2006-May-01 16:49 UTC
[Rd] format.info() versus format.default(): Comments please
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:> format.info(123456)[1] 6 0 0> format(123456, big.mark=",")[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:> 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 > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Maybe Matching Threads
- prettyNum digits=0 not compatible with scientific notation
- prettyNum digits=0 not compatible with scientific notation
- format (PR#14062)
- Bug in format.default(): na.encode does not have any effect for (PR#12318)
- prettyNum digits=0 not compatible with scientific notation