[Rd] rownames() problem with 0-extent arrays (PR#9136)

Raubertas, Richard richard_raubertas at merck.com
Wed Aug 16 16:57:05 CEST 2006


Prof Ripley,
Thanks for your reply.  I've inserted a couple of inline 
comments below.

Rich Raubertas

> -----Original Message-----
> From: Prof Brian Ripley [mailto:ripley at stats.ox.ac.uk] 
> Sent: Wednesday, August 16, 2006 7:21 AM
> To: Raubertas, Richard
> Cc: r-devel at stat.math.ethz.ch
> Subject: Re: [Rd] rownames() problem with 0-extent arrays (PR#9136)
> 
> 
> R-bugs is not the place to ask questions, see the FAQ ....

Yes, I should have sent a separate message.

> 
> On Fri, 11 Aug 2006, richard_raubertas at merck.com wrote:
> 
> [...]
> 
> > A separate but related question (not a bug) has to do with 
> the handling
> > of dimnames for 0-extent arrays.  If an array starts out 
> with non-NULL
> > dimnames and is subscripted down to have 0-extent, the 
> corresponding 
> > component is set to NULL, rather than character(0):
> 
> and that dimension does not have any names, so this is appropriate.

I think the question of whether a dimension has names or not 
should be independent of the extent of that dimension.  (My reason 
for raising the issue was that some code I was writing would 
be cleaner if "dimension has names" and "extent of dimension" were 
orthogonal concepts.)  Under that premise, there is a difference 
between NULL (no names) and character(0) (names).  

It appears you don't agree with my premise, and I can see how a 
discussion about naming things that don't exist could get rather 
metaphysical.  So I have worked around the issue in my code.

> 
> > dimnames(tmp[0,,drop=FALSE])   # first component is NULL
> > 
> > Why is that?  Note that this is different from how data frames are 
> > handled:
> > 
> > tmp.df <- data.frame(tmp)
> > dimnames(tmp.df[0,])  # first component is character(0)
> 
> Data frames do not have 'dimnames', and what is reported by 
> the accessor 
> function is list(row.names(x), names(x)), both of which are 
> required to be 
> character vectors.  Indeed, as the help file says
> 
>   For the \code{"data.frame"} method both dimnames must be 
> non-null, and
>   the rownames must contain no duplicates nor missing values.
> 
> > The description in ?dimnames seems to allow character(0) components 
> > of dimnames, 
> > 
> >      "The dimnames of a matrix or array can be 'NULL' or a 
> list of the
> >      same length as 'dim(x)'.  If a list, its components are either
> >      'NULL' or a character vector the length of the appropriate
> >      dimension of 'x'."
> 
> That is accurate.
> 
> > yet the implementation seems to resist them:
> > 
> > tmp2 <- tmp[0,,drop=FALSE]
> > dimnames(tmp2) <- list(character(0), LETTERS[1:3])
> > dimnames(tmp2)  #  still NULL
> > 
> > So my question is whether it would be reasonable to change 
> 'dimnames'
> > and/or "dimnames<-" to use (or at least allow) character(0) 
> rather than 
> > NULL for array dimensions of 0 extent.
> 
> Why would it be desirable to have two equivalent 
> representations of the 
> same thing (no names)?  As you could easily have found out, 
> the C code 
> replaces a zero-length vector by NULL.
> 
> -- 
> 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
> 
>



More information about the R-devel mailing list