From maechler at stat.math.ethz.ch  Fri Mar  7 10:39:12 2003
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Fri Mar  7 10:39:21 2003
Subject: [Rd] Re: Proposal for suppressing row labels.
In-Reply-To: <200303061942.h26JgpC19908@gelfand.math.unb.ca>
References: <200303061942.h26JgpC19908@gelfand.math.unb.ca>
Message-ID: <15976.26816.73740.358350@gargle.gargle.HOWL>

>>>>> "Rolf" == Rolf Turner <rolf@math.unb.ca>
>>>>>     on Thu, 6 Mar 2003 15:42:51 -0400 (AST) writes:

I think this definitely belongs to the R-devel mailing list
-- to which I'm diverting it now.

    Rolf> Very often when I print a data frame (particularly when sink()-ing to
    Rolf> a file I do NOT want the row labels (which are in such cases usually
    Rolf> 1, 2, ... nrow(x), where x is the data frame in question).  I can of
    Rolf> course edit these out ``by hand'', but that's a bit of a pain in the
    Rolf> pohutukawa.

    Rolf> I recently discovered (reading the help on print.data.frame
    Rolf> meticulously, and following it through to print.matrix) that
    Rolf> I CAN suppress these row names by executing, e.g.

    >> print(x,rowlab=rep("",nrow(x)))

    Rolf> However it would be ever-so-slightly nicer (require somewhat fewer
    Rolf> key strokes) if there were an option to print.data.frame that would
    Rolf> allow suppression of row names.  E.g. an argument ``srn=FALSE''.
    Rolf> (Where ``srn'' stands for ``suppress row names''.)

Alternatively, I'd prefer allowing  rowlab = ""
which looks nice enough and doesn't need a new argument

BTW: You've helped uncovering a problem in R-devel: 
  There, `rowlab' and `collab' are currently silently not working  :
  print.matrix() doesn't have them anymore, only prmatrix() does
  {which is not the same any more}

 -- hmm...

    Rolf> I have written my own simple minded implementation of this option,
    Rolf> given below in case anyone else out there may have shared my
    Rolf> frustration at being unable to figure out how to suppress row names.

The drawback of such an approach is that you need explicit
print(.) calls (which may look a bit ugly).
An alternative approach is to use default printing for a new
object made from the original one --- though I must admit I'm
not 100% convinced it's appropriate for your original proposal:

Relatedly (but not identically aimed), I have had an alternative
implemented from an S-news "discussion" including Bill Venables
of about 1993. 

The way it's here, it's not working for data frames (just for
matrices, but also other arrays), also since data frames must
have unique row names by definition.
But you get the main idea :

empty.dimnames <- function(a)
{
  ## 'Remove' all dimension names from an array for compact printing.
  d <- list(); l <- 0
  for(i in dim(a)) d[[l <- l + 1]] <- rep("", i)
  dimnames(a) <- d
  a
}

with help :
-------------------------------------------------------------------------

empty.dimnames            package:sfsmisc            R Documentation

Empty Dimnames of an Array.

Description:

     `Remove' all dimension names from an array for compact printing.

Usage:

     empty.dimnames(a)

Arguments:

       a: an `array', especially a matrix.

Value:

     Returns `a' with its dimnames replaced by empty character strings.

Author(s):

     Bill Venables / Martin Maechler, Sept 1993.

See Also:

     `unname' removes the dimnames.

Examples:

     empty.dimnames(diag(5)) # looks much nicer

     (a <- matrix(-9:10, 4,5))
     empty.dimnames(a) # nicer, right?

-------------------------------------------------------------------------


[Rd] Re: Proposal for suppressing row labels.
Martin Maechler