Apparently, indexing a list with attributes returns a list without the attributes.
> l <- list(a=1:3, b=7)
> attr(l, 'x') <- 67
> l
$a
[1] 1 2 3
$b
[1] 7
attr(,"x")
[1] 67
> l[c('a','b')]
$a
[1] 1 2 3
$b
[1] 7
Attributes are gone. Is it possible to index a list while preserving its attributes?
Here is such a subset function. Note that it is important to not try to overwrite the ‘names’ attribute.
Trying to simply assign the attributes will result in the subset failing if it actually does any subsetting.