char.matrix Object to Make a Formatted Table
char.matrix object to make a formatted table
print.char.matrix(x, ..., hsep = "|", vsep = "-", csep = "+",
print.it = T, prefix.width,
min.colwidth = .Options$digits,
abbreviate.dimnames = T,
page.width = .Options$width)
char.matrix. A
char.matrix is
a matrix of strings with the class
char.matrix (character matrix)
attached to it.
The strings typically have "\n"s in them, meaning that the
string should be broken into lines at those points.
Use
print.char.matrix to justify each line
of the printed table in its cell and to separate the cells
with lines made of the
hsep and
vsep characters.
If x has
dimnames, they will be used as the row and column labels
of the table.
If the
dimnames list has names, they will be printed above the table.
print.default may be supplied here.
hsep.
char.matrix object).
If FALSE, the
page.width argument will be ignored -- the table will
not be broken in groups of columns, each group as wide as the page.
min.colwidth
characters wide.
abbreviate function)
the row and column names in order to fit into the space available for
them. If FALSE, those names will be truncated.
page.width it will be broken
up into pieces that fit. The row labels will be printed before
each piece.
This was written as a support function for
print.crosstabs and
details may be changed as required for other print methods.
a <- matrix(c("One Line","Two\nLines","Three\nShort\nLines",
"Four words, one line"), 2, 2)
class(a) <- "char.matrix"
a
# Produces the following output:
# +--------+--------------------+
# |One Line|Three |
# | |Short |
# | |Lines |
# +--------+--------------------+
# |Two |Four words, one line|
# |Lines | |
# +--------+--------------------+
# assign dimnames with names.
dimnames(a) <- list(Rows = c("Row 1","Row 2"), Cols = c("Col 1", "Col 2"))
print(a, vsep="")
# Produces the following output:
# Rows |Cols
# |Col 1 |Col 2 |
# Row 1 |One Line|Three |
# | |Short |
# | |Lines |
# Row 2 |Two |Four words, one line|
# |Lines | |
# Build a complex table using print.it = F
aa <- matrix( c("Overall\nLabel", print(a, print.it = F)), 1, 2)
class(aa)<-"char.matrix"
aa
# Produces the following output:
# +-------+--------------------------------------+
# |Overall|Rows |Cols |
# |Label | |Col 1 |Col 2 ||
# | |-------+--------+--------------------+|
# | |Row 1 |One Line|Three ||
# | | | |Short ||
# | | | |Lines ||
# | |-------+--------+--------------------+|
# | |Row 2 |Two |Four words, one line||
# | | |Lines | ||
# | |-------+--------+--------------------+|
# | | |
# +-------+--------------------------------------+