[Rd] length-0 list as dimnames
simon.urbanek at r-project.org
Wed Jun 6 01:43:33 CEST 2012
On Jun 5, 2012, at 7:37 PM, Benilton Carvalho wrote:
> I'm working on a package and observed a behaviour that was suggested
> to be incompatible with the documentation.
> The code below:
> x <- matrix(1:4, 2)
> dimnames(x) <- list()
> works just fine. But checking the documentation for dimnames(), it
> states that if value is a list "its components are either 'NULL' or a
> character vector with positive length of the appropriate dimension of
> Should dimnames() return an error on the example above?
No, from the docs:
The replacement method for arrays/matrices coerces vector and
factor elements of ‘value’ to character, but does not dispatch
methods for ‘as.character’. It coerces zero-length elements to
‘NULL’, and a zero-length list to ‘NULL’.
you are using a 0-length list, so it is coerced to NULL.
> Thank you very much for your attention and time,
> R-devel at r-project.org mailing list
More information about the R-devel