HenrikBengtsson / listenv

R package: listenv - Environments Behaving As Lists
https://listenv.futureverse.org
30 stars 2 forks source link

Add x[subset] to effectively be short for as.list(x)[subset]? #2

Closed HenrikBengtsson closed 9 years ago

HenrikBengtsson commented 9 years ago

Question

To better emulate list:s, should subsetting via [ also be supported?

Example

Currently, we get:

> x <- listenv()
> x$a <- 1
> x$b <- 2
> x$c <- 3
> as.list(x)[2:3]
$b
[1] 2

$c
[1] 3

> x[2:3]
Error in x[2:3] : object of type 'environment' is not subsettable

After adding support for [, we should get a list:

> x[2:3]
$b
[1] 2

$c
[1] 3

...or a list environment? (see below).

Requirements

HenrikBengtsson commented 9 years ago

Decided to have x[1:3] return a list environment.