I think we need to consult a lawyer on this one ... :-)
?Extract says that an empty index is "most often used" ... . This is a
vague comment on use, **not** an exact specification of what x[] does.
The R language manual appears to be out of date or wrong: it specifies
that "irrelevant" attributes are anything but names and dimnames in
"Only names and in multi-dimensional arrays dim and dimnames
attributes are retained." As you noted, this is false:
> x <- matrix(1:6,3,2)
> x[]
[,1] [,2]
[1,] 1 4
[2,] 2 5
[3,] 3 6
> attr(x,"fy")<- "funny"
> x
[,1] [,2]
[1,] 1 4
[2,] 2 5
[3,] 3 6
attr(,"fy")
[1] "funny"
> x[]
[,1] [,2]
[1,] 1 4
[2,] 2 5
[3,] 3 6
attr(,"fy")
[1] "funny" ## this contradicts the Language definition manual passage
above
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Fri, Dec 11, 2015 at 1:09 PM, S?bastien Durier
<sdurier.stat at gmail.com> wrote:> Hello,
>
> In ?Extract, one can read "An empty index selects all values: this is
most
> often used to replace all the entries but keep the attributes"
> No example is given but if x a vector I interpret this sentence as
"x[]".
> And in fact, all attributes seem to be preserved by this indexing.
> But in the R language manual
>
(https://cran.r-project.org/doc/manuals/r-devel/R-lang.html#Indexing-by-vectors),
> the following passage puzzles me : "Empty. The expression x[] returns
x, but
> drops ?irrelevant? attributes from the result." I must misunderstand
> something because it sounds contradictory with the help page.
>
> Thank you
>
> SD
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.