Martin Maechler maechler at stat.math.ethz.ch
Mon Oct 3 15:04:00 CEST 2005

```>>>>> "BDR" == Prof Brian Ripley <ripley at stats.ox.ac.uk>
>>>>>     on Mon, 3 Oct 2005 09:44:47 +0100 (BST) writes:

BDR> 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)

BDR> 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.

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

I was lead to my conclusion by the same help page, reading

>> Arguments:
>>
>>    x: a matrix-like R object, with at least two dimensions for 'colnames'.

from which I concluded an error was appropriate for 'colnames'
when 'x' doesn't have two dimensions.