From beniltoncarvalho at gmail.com  Wed Jun  6 01:51:53 2012
From: beniltoncarvalho at gmail.com (Benilton Carvalho)
Date: Wed, 6 Jun 2012 00:51:53 +0100
Subject: [Rd] length-0 list as dimnames
In-Reply-To: <628CCADF-6BCC-4FEB-A6A0-D32F671D10BC@r-project.org>
References: <CAO-arWNY1CBgpYND748v-796BR7SoctfeghZYAixdqJzq=3D=w@mail.gmail.com>
	<628CCADF-6BCC-4FEB-A6A0-D32F671D10BC@r-project.org>
Message-ID: <CAO-arWMj+xMgFPSwFP2Svsh1b==onhs60E+zkYw0nq2Ej_8J9w@mail.gmail.com>

Thank you very much for pointing me to the correct part of the
documentation (and apologies for that), Simon. Very much appreciated,
b

On 6 June 2012 00:43, Simon Urbanek <simon.urbanek at r-project.org> wrote:
>
> On Jun 5, 2012, at 7:37 PM, Benilton Carvalho wrote:
>
>> Hi,
>>
>> 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
>> x".
>>
>> 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.
>
> Cheers,
> Simon
>
>
>
>> Thank you very much for your attention and time,
>>
>> benilton
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>>
>



[Rd] length-0 list as dimnames
Benilton Carvalho