Bug 16817 - Do not print a blank line when printing a matrix with blank named dimnames
Summary: Do not print a blank line when printing a matrix with blank named dimnames
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: I/O (show other bugs)
Version: R 3.2.4
Hardware: All All
: P5 minor
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2016-04-10 18:51 UTC by Tim Hesterberg
Modified: 2016-04-10 18:51 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Hesterberg 2016-04-10 18:51:46 UTC
My request is that no blank line be printed, when printing a matrix with
named dimnames, where the column name is blank.

Details:
Printing result of table() often gives an initial blank line:
> table(CO2$Type, CO2$Treatment)
             
              nonchilled chilled
  Quebec              21      21
  Mississippi         21      21

I find this separation often results in confusing formatting, particulary
when printing multiple tables, e.g. using lapply.

Looking inside print.table, I think this is related to printing of
ordinary matrices, where dimnames with named components leave space for
names, even when names are not present:

> # usual case, no names on dimnames; no blank line
> matrix(1:4, 2, dimnames = list(c("x","y"), c("a","b")))
  a b
x 1 3
y 2 4
> # intended behavior
> matrix(1:4, 2, dimnames = list(row = c("x","y"), col = c("a","b")))
   col
row a b
  x 1 3
  y 2 4
> # This results in a blank line when the column name is not present:
> matrix(1:4, 2, dimnames = list(row = c("x","y"), c("a","b")))
   
row a b
  x 1 3
  y 2 4
> # Intended behavior:
> with(CO2, table(Type, Treatment))
             Treatment
Type          nonchilled chilled
  Quebec              21      21
  Mississippi         21      21