New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check recursive indexing and NULLs #173
Comments
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 cc @jennybc |
What should happen if you do recursive indexing on an object that is not recursive? x <- list(1:10)
index(x, 1, 2, 3) Should that be an error? |
That would be consistent with base R letters[[1]][[2]]
#> Error in letters[[1]][[2]] : subscript out of bounds |
@lionel- I think the point here is to not be consistent with base R - we need a function that always returns a value so you can use it to regularise irregular data structures |
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. |
@lionel- the default value will be user selectable |
Often wish for something along the lines of Options: https://fsharpforfunandprofit.com/posts/the-option-type/ |
R's 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). |
Yeah ... Similar but still not the same... |
No actually it's the same. I thought Fsharp |
Take a look at the differences mentioned in the article. Some of them would apply still... |
I did read the article. If you'd like to continue this discussion let's do it by mail so we don't ping Hadley all the time ;) |
Not necessary :) Point was more that |
And what if |
IYSS :) |
I think I have an implementation - I'm going to work on some tests and then I'll check it in, and @jennybc can play around with it and give me her feedback :) (for now you'll need to use |
I'm pretty sure this is solid now |
Maybe this is an R bug? Should at least bring up on R-devel, and consider a work around (
tryCatch()
?) inas_function.character()
The text was updated successfully, but these errors were encountered: