Check recursive indexing and NULLs #173
I think we need a new recursive indexing operator that behaves consistently with respect to missing values.
list(a = list())[[c("a", "b", "c")]] #> Error in list(a = list())[[c("a", "b", "c")]]: no such index at level 2 list(a = list())[["a"]][["b"]][["c"]] #> NULL
It would also be nice to have be able to mix subsetting by name and position, so you could do (e.g.)
x <- list(a = list(list(), list(c = 3)) x[[list("a", 1, "c")]]
And we also need to be able to specify a default value to use when the indexed object does not - this makes it easier to use with
For efficiency, this will need to be implemented in C
ok. Then IIUC it shouldn't be an error since recursive data structures always end with a non-recursive vector (or a NULL value).
We can return a NA or a NULL, but in either case we'll have the problem of distinguishing being actual NA/NULL values and implicitly filled ones. Maybe better to go with NULL then since NAs are used for actual data so we shouldn't have ambiguity for these.
But this should probably be tackled in R core and not a package. Not sure it's possible to make NULL a proper SEXP type without breaking compatibility though (it's currently a singleton).