-
Notifications
You must be signed in to change notification settings - Fork 272
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
Strict pluck #482
Comments
We could call it |
Were you thinking something like the following (but without the test.list <- list(a = 1:5, b = letters[1:5], c = list(abc = 123))
test.atom <- 1:10
> # strict_pluck()
> pluck(NULL, integer(0), strict = TRUE)
Error: `.x` must not be NULL.
> pluck(NULL, 100, strict = TRUE)
Error: `.x` must not be NULL.
> pluck(NULL, "adsaf", strict = TRUE)
Error: `.x` must not be NULL.
> pluck(NULL, NA_integer_, strict = TRUE)
Error: `.x` must not be NULL.
> pluck(test.list, integer(0), strict = TRUE)
Error: Can't find index.
> pluck(test.list, 100, strict = TRUE)
Error: Can't find index.
> pluck(test.list, "adsaf", strict = TRUE)
Error: Can't find index.
> pluck(test.list, NA_integer_, strict = TRUE)
Error: Can't find index.
> pluck(test.atom, integer(0), strict = TRUE)
Error: Can't find index.
> pluck(test.atom, 100, strict = TRUE)
Error: Can't find index.
> pluck(test.atom, "adsaf", strict = TRUE)
Error: Can't find index.
> pluck(test.atom, NA_integer_, strict = TRUE)
Error: Can't find index. |
Exactly! |
A PR would be great 😄 |
So, I also have this working for environments and S4 objects. For environments, it errors if the object doesn't exist in the environment, and for S4 if the object doesn't have the desired slot. This would the desired behaviour, right? The other big one is indexing by function, but (correct me if I'm wrong) I don't think we can really make this strict as it relies on whatever that function's behaviour is. |
That all sounds correct to me |
In base R,
[[
sometimes returns an error and sometimes returnsNULL
:row[[col]]
NULL
NULL
NULL
NULL
NULL
NULL
NULL
pluck()
eliminates this inconsistently by (effectively) always returnNULL
. We need a strict equivalent that eliminates the inconsistency in the opposite direction: by always throwing an error.The text was updated successfully, but these errors were encountered: