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
To minimize overhead, and to avoid blocking scenarios (e.g. via futures), the subsetting should implemented such that only the elements requested are queried/touched/retrieved and all other are ignored.
Should it return a list or a listenv? Note that it is not possible to return a listenv while not copying the elements. In other words, doing y <- x[1:2]; y[1] <- 4 will not change x[1]. Because of this, does it make more sense to return a list? Also, note that environment cannot be subetted; if they would then listenv would also be subsettable automatically.
Question
To better emulate list:s, should subsetting via
[
also be supported?Example
Currently, we get:
After adding support for
[
, we should get a list:...or a list environment? (see below).
Requirements
list
or alistenv
? Note that it is not possible to return alistenv
while not copying the elements. In other words, doingy <- x[1:2]; y[1] <- 4
will not changex[1]
. Because of this, does it make more sense to return alist
? Also, note thatenvironment
cannot be subetted; if they would thenlistenv
would also be subsettable automatically.