printSpMatrix
Format and Print Sparse Matrices Flexibly
Description
Format and print sparse matrices flexibly. These are the “workhorses” used by the format
, show
and print
methods for sparse matrices. If x
is large, printSpMatrix2(x)
calls printSpMatrix()
twice, namely, for the first and the last few rows, suppressing those in between, and also suppresses columns when x
is too wide.
printSpMatrix()
basically prints the result of formatSpMatrix()
.
Usage
formatSpMatrix(x, digits = NULL, maxp = 1e9, cld = getClassDef(class(x)), zero.print = ".", col.names, note.dropping.colnames = TRUE, uniDiag = TRUE, align = c("fancy", "right")) printSpMatrix(x, digits = NULL, maxp = max(100L, getOption("max.print")), cld = getClassDef(class(x)), zero.print = ".", col.names, note.dropping.colnames = TRUE, uniDiag = TRUE, col.trailer = "", align = c("fancy", "right")) printSpMatrix2(x, digits = NULL, maxp = max(100L, getOption("max.print")), zero.print = ".", col.names, note.dropping.colnames = TRUE, uniDiag = TRUE, suppRows = NULL, suppCols = NULL, col.trailer = if(suppCols) "......" else "", align = c("fancy", "right"), width = getOption("width"), fitWidth = TRUE)
Arguments
x | an R object inheriting from class |
digits | significant digits to use for printing, see |
maxp | integer, default from |
cld | the class definition of |
zero.print | character which should be printed for structural zeroes. The default |
col.names | logical or string specifying if and how column names of |
note.dropping.colnames | logical specifying, when |
uniDiag | logical indicating if the diagonal entries of a sparse unit triangular or unit-diagonal matrix should be formatted as |
col.trailer | a string to be appended to the right of each column; this is typically made use of by |
suppRows, suppCols | logicals or |
align | a string specifying how the |
width | number, a positive integer, indicating the approximately desired (line) width of the output, see also |
fitWidth | logical indicating if some effort should be made to match the desired |
Details
- formatSpMatrix:
-
If
x
is large, only the first rows making up the approximately firstmaxp
entries is used, otherwise all ofx
..formatSparseSimple()
is applied to (a dense version of) the matrix. Then,formatSparseM
is used, unless in trivial cases or for sparse matrices withoutx
slot.
Value
formatSpMatrix() | returns a character matrix with possibly empty column names, depending on |
printSpMatrix*() | return |
Author(s)
Martin Maechler
See Also
the virtual class sparseMatrix
and the classes extending it; maybe sparseMatrix
or spMatrix
as simple constructors of such matrices.
The underlying utilities formatSparseM
and .formatSparseSimple()
(on the same page).
Examples
f1 <- gl(5, 3, labels = LETTERS[1:5]) X <- as(f1, "sparseMatrix") X ## <==> show(X) <==> print(X) t(X) ## shows column names, since only 5 columns X2 <- as(gl(12, 3, labels = paste(LETTERS[1:12],"c",sep=".")), "sparseMatrix") X2 ## less nice, but possible: print(X2, col.names = TRUE) # use [,1] [,2] .. => does not fit ## Possibilities with column names printing: t(X2) # suppressing column names print(t(X2), col.names=TRUE) print(t(X2), zero.print = "", col.names="abbr. 1") print(t(X2), zero.print = "-", col.names="substring 2")
Copyright (©) 1999–2012 R Foundation for Statistical Computing.
Licensed under the GNU General Public License.