Print a char.matrix Object to Make a Formatted Table

DESCRIPTION:

Print a char.matrix object to make a formatted table

USAGE:

print.char.matrix(x, ..., hsep = "|", vsep = "-", csep = "+", 
                  print.it = T, prefix.width,  
                  min.colwidth = .Options$digits, 
                  abbreviate.dimnames = T,  
                  page.width = .Options$width) 

REQUIRED ARGUMENTS:

x
An object of class 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.

OPTIONAL ARGUMENTS:

...
Arguments used by print.default may be supplied here.
hsep
horizontal separator character, printed between columns of the table. Use "" for no separation and a multicharacter string for several columns of separation.
vsep
vertical separator character, printed between rows of the table. Use "" for no separation and a multicharacter string for several lines of separation.
csep
"cross" separator, printed where the horizontal and vertical separators cross. It should be a single character string with as many characters as hsep.
print.it
logical flag. If TRUE, it will print the formatted table. If FALSE, it will return a character string of the lines it would have printed (this output made be used as an entry in another 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.
prefix.width
number of character spaces to allow for the row labels.
min.colwidth
minimum width of any column. The columns are made wide enough to fit all their entries in them, but are made at least min.colwidth characters wide.
abbreviate.dimnames
logical flag. If TRUE, the function will abbreviate (using the 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
If the formatted table is wider than page.width it will be broken up into pieces that fit. The row labels will be printed before each piece.

VALUE:

The first argument is returned.

SIDE EFFECTS:

A formatted table is printed.

NOTE:

This was written as a support function for print.crosstabs and details may be changed as required for other print methods.

SEE ALSO:

, .

EXAMPLES:

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   |                    || 
#  |       |-------+--------+--------------------+| 
#  |       |                                      | 
#  +-------+--------------------------------------+