Re: [Rd] undocumented name mangling during unlist?

From: Seth Falcon <>
Date: Tue 09 Jan 2007 - 17:43:51 GMT

Prof Brian Ripley <> writes:

> On Mon, 8 Jan 2007, Seth Falcon wrote:
>> The documentation for unlist says:
>> By default, 'unlist' tries to retain the naming information
>> present in 'x'. If 'use.names = FALSE' all naming information is
>> dropped.
>> Hence, I find it odd that I see the following:
>> > b <- list("highway1"=1:5)
>> > unlist(b)
>> highway11 highway12 highway13 highway14 highway15
>> 1 2 3 4 5
>> I suspect this is essential behavior for something or other, but it
>> seems that this approach is inefficient for large lists and in many
>> contexts does not preserve names, but invents new ones.
> There is the information that the entries came from element "highway1"
> which needs to be preserved.

In my view, preserving is not the same as creating a new name where the original is a substring.

> c() and unlist() share code, and both try to create different names
> for elements of different origin.

I guess I don't understand. In my example, aren't the elements all of the same origin (from the highway1 entry of the list)?

Granting a different interpretation of origin, it seems the attempt is not very complete:

    v2 <- list(a=rep(1, 2), b=rep(2, 2), a=rep(3, 2))     unlist(v2) ## names are _not_ unique     a1 a2 b1 b2 a1 a2
     1 1 2 2 3 3

> Why is this 'inefficient' (names are optional) and what do you
> propose that meets the conditions?

Could the origin name simply be repeated?

  highway1 highway1 highway1 highway1 highway1

         1 2 3 4 5

Efficiency could be gained by reusing the CHARSXP to name all elements instead of having to created new strings for each name.

+ seth mailing list Received on Wed Jan 10 14:13:20 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 10 Jan 2007 - 13:31:12 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.