From murdoch.duncan at gmail.com  Tue Feb 26 14:12:06 2013
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Tue, 26 Feb 2013 08:12:06 -0500
Subject: [Rd] double bracket stripping names
In-Reply-To: <512C8EB1.8060401@pburns.seanet.com>
References: <512C8EB1.8060401@pburns.seanet.com>
Message-ID: <512CB4A6.4060506@gmail.com>

On 13-02-26 5:30 AM, Patrick Burns wrote:
> Is it on purpose that `[[` strips the
> names when used on an atomic vector?
>
>   > c(a=1, b=2)[1]
> a
> 1
>   > c(a=1, b=2)[[1]]
> [1] 1


Yes, as Brian said.  And this makes sense:  the names are a property of 
the container, not a property of the contents.  Using single brackets 
creates a new container with a subset of the elements.  Using double 
brackets extracts an element.

The fact that there's no way to hold a number other than in a length one 
container means that the results are both length one containers, but 
conceptually there's a difference between subsetting and extracting. 
Perhaps at some distant date in the future scalar numbers will be 
possible, and then maybe c(a=1, b=2)[[1]] would give one.

Duncan Murdoch



[Rd] double bracket stripping names
Duncan Murdoch