format() of a character matrix converts to vector (PR#960)
Thanks. There is an easy fix. In format.default
f.char <- function(x, justify) {
if(length(x) <= 1) return(x)
nc <- nchar(x)
w <- max(nc)
all <- substring(paste(rep(" ", w), collapse=""), 1, w-nc)
res <- if(justify == "left") paste(x, all, sep="")
else paste(all, x, sep="")
dim(res) <- dim(x)
res
}
On Thu, 31 May 2001 John.Peters@tip.csiro.au wrote:
Using R 1.2.3 under both windows 95 and linux, format() works fine on a numerical matrix, but converts a character matrix to a vector, apparently omitting to convert it back to a matrix:
a_matrix(c("axx","b","c","d","e","f","g","h"),nrow=2)
a
[,1] [,2] [,3] [,4] [1,] "axx" "c" "e" "g" [2,] "b" "d" "f" "h"
format(a)
[1] "axx" "b " "c " "d " "e " "f " "g " "h "
format(a,justify="right")
[1] "axx" " b" " c" " d" " e" " f" " g" " h"
format(a,justify="left")
[1] "axx" "b " "c " "d " "e " "f " "g " "h "
format(a,justify="none")
[,1] [,2] [,3] [,4] [1,] "axx" "c" "e" "g" [2,] "b" "d" "f" "h" Many thanks ---------------------------------------------------------------------------- John Peters CSIRO National Measurement Laboratory PO Box 218 Phone: +61 2 9413 7503 Lindfield NSW 2070 Fax: +61 2 9413 7202 Australia Internet: John.Peters@tip.CSIRO.AU ---------------------------------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._