From ripley at stats.ox.ac.uk  Tue May 20 17:01:42 2003
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Tue May 20 17:02:04 2003
Subject: (PR#3058) [Rd] FW: print.matrix incorrectly formatting string
	matrixes when right=T
In-Reply-To: <200305201341.h4KDfG2b024847@pubhealth.ku.dk>
Message-ID: <Pine.LNX.4.44.0305201559060.23387-100000@gannet.stats>

Fixed for R-patched.

Note that right=TRUE (sic) is not used for numeric matrices: it is the 
default and cannot be altered.

On Tue, 20 May 2003 gregory_r_warnes@groton.pfizer.com wrote:

> 
> > When printing a string matrix with right=TRUE and na.print specified, an
> > incorrect amount of spaced is provided for NA columns leading to incorrect
> > formatting:
> > 
> > 
> > > a <- matrix( c(NA, "a", "b", "10",
> > +                NA, NA,  "d", "12",
> > +                NA, NA,  NA,  "14"),
> > +              byrow=T, ncol=4 )
> > > print(a) # correct
> >      [,1] [,2] [,3] [,4]
> > [1,] NA   "a"  "b"  "10"
> > [2,] NA   NA   "d"  "12"
> > [3,] NA   NA   NA   "14"
> > > print(a, right=T) # correct
> >      [,1] [,2] [,3] [,4]
> > [1,]   NA  "a"  "b" "10"
> > [2,]   NA   NA  "d" "12"
> > [3,]   NA   NA   NA "14"
> > > print(a, right=T, na.print=" ") # wrong
> >      [,1] [,2] [,3] [,4]
> > [1,]      "a"  "b" "10"
> > [2,]          "d" "12"
> > [3,]             "14"
> > > print(a, right=T, na.print="      ") # wrong
> >      [,1]   [,2]   [,3]   [,4]
> > [1,]               "a"    "b" "10"
> > [2,]                          "d" "12"
> > [3,]                                  "14"
> > >  
> > 
> > 
> > This does not occur with numeric matrixes:
> > 
> > > a <- matrix( c(NA, 1.0, 2.0, 3.0,
> > +                NA, NA,  4.0, 5.0,
> > +                NA, NA,   NA, 6.0 ),
> > 
> > +                byrow=T, ncol=4 )
> > > print(a)
> >      [,1] [,2] [,3] [,4]
> > [1,]   NA    1    2    3
> > [2,]   NA   NA    4    5
> > [3,]   NA   NA   NA    6
> > > print(a,right=T)
> >      [,1] [,2] [,3] [,4]
> > [1,]   NA    1    2    3
> > [2,]   NA   NA    4    5
> > [3,]   NA   NA   NA    6
> > > print(a,right=T,na.print=" ")
> >      [,1] [,2] [,3] [,4]
> > [1,]         1    2    3
> > [2,]              4    5
> > [3,]                   6
> > > print(a, right=T, na.print="      ")
> >        [,1]   [,2]   [,3] [,4]
> > [1,]             1      2    3
> > [2,]                    4    5
> > [3,]                         6
> > >
> > 

-- 
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


(PR#3058) [Rd] FW: print.matrix incorrectly formatting string matrixes when right=T
Prof Brian Ripley