From ripley@stats.ox.ac.uk  Fri Sep 25 17:51:06 1998
From: ripley@stats.ox.ac.uk (Prof Brian Ripley)
Date: Fri, 25 Sep 1998 17:51:06 +0100 (BST)
Subject: format(numericmatrix, ...) : proposal for a change
In-Reply-To: <13835.46887.262990.724831@galadriel.ci.tuwien.ac.at>
Message-ID: <Pine.GSO.3.96.980925173322.16892A-100000@toucan.stats>

On Fri, 25 Sep 1998, Friedrich Leisch wrote:

> 
> Columnwise formatting would be fine with me ... could you just leave
> the current behavior as option? In many cases matrix-wide formatting
> is useful!
> 

There are at least three different versions of format.default in different
versions of S-PLUS, so some of us have learnt to do this very
defensively. 


Columnwise formatting would be OK, but I don't think padding with spaces
rather than zeroes is acceptable. To be fair to S-PLUS, there are options
to change that, and if you are going to change this you might like to look
at adding nsmall and justify.

nsmall:   the minimum number of digits to appear to the right  of
       the decimal.
justify:    character string  giving  the  justification  of  the
       numbers  relative  to each other.  The choices are "none",
       "left", "right" and  "decimal".   Only  the  first  letter
       needs to be given.

At least as defined, format.default does not know about columns, and your
example is misleading: (in S)

> aa <- rbind(1:7, rnorm(7))
> format(aa, digits=7)
             [,1]         [,2]         [,3]         [,4]         [,5] 
[1,] " 1        " " 2        " " 3        " " 4        " " 5        "
[2,] "-0.6755785" "-0.5184718" "-0.665482 " " 2.07566  " " 0.4811527"

             [,6]         [,7] 
[1,] " 6        " " 7        "
[2,] "-0.708872 " "-0.4482897"

What do you actually want that to do? I think there is a strong case for
leaving format.default alone, and writing format.matrix and/or
format.data.frame.

Note that the digits= argument is documented differently in R and in S.


> 
> .f
> 
> 
> >>>>> On Fri, 25 Sep 1998 17:21:22 +0200,
> >>>>> Martin Maechler (MM) wrote:
> 
> MM> Since format, i.e.,  format.default(.), is a pretty basic function I
> MM> thought I'd ask  before just changing it...
> 
> MM> 	aa <- cbind(1:7, rnorm(7))
> MM> 	format(aa)
> MM> or
> MM> 	format(aa, digits=7)
> 
> MM> looks like
> 
> MM>       [,1]         [,2]        
> MM>  [1,] " 1.0000000" " 0.2406669"
> MM>  [2,] " 2.0000000" "-0.4973221"
> MM>  [3,] " 3.0000000" " 0.4672260"
> MM>  [4,] " 4.0000000" " 0.4794697"
> MM>  [5,] " 5.0000000" "-1.0234062"
> MM>  [6,] " 6.0000000" "-0.3430790"
> MM>  [7,] " 7.0000000" "-0.1847634"
> 
> MM> which is pretty ugly.
> 
> MM> What I'd rather want is that each column be formatted independently, i.e.,
> MM> (almost) the result I'd currently get from
> 
> MM> 	apply(aa, 2, format, digits=7)
> 
> MM> ---
> MM> S gives something like
> 
> S> format(aa, digits=7)
> MM>                [,1]           [,2] 
> MM> [1,] " 1          " " 0.07364329 "
> MM> [2,] " 2          " "-0.7101905  "
> MM> [3,] " 3          " " 0.005834993"
> MM> [4,] " 4          " " 0.3425964  "
> MM> [5,] " 5          " " 0.8825893  "
> MM> [6,] " 6          " " 0.9540261  "
> MM> [7,] " 7          " "-0.4660654  "
> 
> MM> (which is different from the above apply(...) by using strings which all
> MM>  have the identical number of characters).
> 
> MM> Proposal: I'd like to have format(<numeric matrix>, ...) change to do
> MM> 	COLUMNWISE formatting, either the way as apply(..) above, or
> MM> 	returning strings of identical length (somewhat like S above).
> 
> MM> Note  I don't intend to copy S-plus'  ``full mess'' of doing it :
> MM> In S-plus  
> MM> 	format(aa)
> MM> and	format(aa, digits = .Options$digits)
> MM> are very different even though .Options$digits *IS* the default for
> MM> digits...
> 
> MM> Also, we have formatC(.) which very useful for quite a few problems...
> 
> MM> ---------------
> 
> MM> What do we ( you !) want ?
> 
> MM> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> MM> r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> MM> Send "info", "help", or "[un]subscribe"
> MM> (in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
> MM> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 

-- 
Brian D. Ripley,                  ripley@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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


format(numericmatrix, ...) : proposal for a change
Prof Brian Ripley