From ripley at stats.ox.ac.uk  Tue Jan  9 17:30:22 2007
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Tue, 9 Jan 2007 16:30:22 +0000 (GMT)
Subject: [Rd] undocumented name mangling during unlist?
In-Reply-To: <m27ivxe6ok.fsf@fhcrc.org>
References: <m27ivxe6ok.fsf@fhcrc.org>
Message-ID: <Pine.LNX.4.64.0701091623480.24672@gannet.stats.ox.ac.uk>

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.  c() and unlist() share code, and both try to 
create different names for elements of different origin.

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

It is probably not coincidental that S3 did this the same way.


>
> /me ducks
>
> + seth
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

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



[Rd] undocumented name mangling during unlist?
Prof Brian Ripley