From ripley at stats.ox.ac.uk  Mon Oct  3 10:44:47 2005
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Mon, 3 Oct 2005 09:44:47 +0100 (BST)
Subject: [Rd] Question about colnames behavior
In-Reply-To: <17216.60355.877530.104575@stat.math.ethz.ch>
References: <433F8EB8.70703@univie.ac.at>
	<17216.60355.877530.104575@stat.math.ethz.ch>
Message-ID: <Pine.LNX.4.61.0510030940050.30152@gannet.stats>

On Mon, 3 Oct 2005, Martin Maechler wrote:

>>>>>> "Erich" == Erich Neuwirth <erich.neuwirth at univie.ac.at>
>>>>>>     on Sun, 02 Oct 2005 09:39:36 +0200 writes:
>
>    Erich> The following code
>    Erich> zzz<-1:10
>    Erich> dim(zzz)<-10
>    Erich> rownames(zzz)
>    Erich> colnames(zzz)
>
>    Erich> yields NULL for the rownames and colnames calls.
>    Erich> Let us set rownames
>
>    Erich> rownames(zzz)<-1:10
>
>    Erich> Now rownames(zzz) returns the expected result, but colnames(zzz)
>    Erich> produces an error:
>    Erich> Error in dn[[2]] : subscript out of bounds
>
>    Erich> So given a onedimensional structure the return behavior of colnames
>    Erich> is different depending on the fact if rownames are set or not.
>
>    Erich> Should the behavior of colnames be changed to make the result
>    Erich> independent from this fact?
>
> yes, thank you, Erich.
> It should give an error also in the 1st  case which is
> BTW identical to
>    zzz <- array(1:10)

Not according to my reading of the help, which says

      The extractor functions try to do something sensible for any
      matrix-like object 'x'.  If the object has 'dimnames' the first
      component is used as the row names, and the second component (if
      any) is used for the col names.

and reading on, I think it should give NULL in both cases.  You could 
argue that a 1D array is not `matrix-like', but that seems a narrow 
interpretation (especially as rownames does work for such arrays).

> Not for R 2.2.0 though, but rather 2.2.1.

Agreed.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] Question about colnames behavior
Prof Brian Ripley