From h.wickham at gmail.com  Tue Feb 26 18:21:33 2013
From: h.wickham at gmail.com (Hadley Wickham)
Date: Tue, 26 Feb 2013 11:21:33 -0600
Subject: [Rd] double bracket stripping names
In-Reply-To: <512CB4A6.4060506@gmail.com>
References: <512C8EB1.8060401@pburns.seanet.com> <512CB4A6.4060506@gmail.com>
Message-ID: <CABdHhvGe-ui+aeZO+bKF0zixbLaM9OsqqOMXhQaNhKFVUZfOag@mail.gmail.com>

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

I like to make  the distinction between simplifying and preserving
subsetting (maybe not the best names but the best I've been able to
come up with).  It's unfortunate (but understandable) that the syntax
is inconsistent between lists and matrices:  x[i] / x[[i]], vs x[i, ,
drop = F], x[i, ]

Hadley


-- 
Chief Scientist, RStudio
http://had.co.nz/



[Rd] double bracket stripping names
Hadley Wickham