-
Notifications
You must be signed in to change notification settings - Fork 274
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
Require strict predicate functions in purrr #591
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hadley
approved these changes
Nov 30, 2018
@@ -64,6 +64,16 @@ reduce2_right(.x = letters[1:4], .y = paste2, .f = c("-", ".", "-")) # working | |||
|
|||
## Minor improvements and fixes | |||
|
|||
* Functions taking predicates (`map_if()`, `keep()`, `some()`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think TRUE
or FALSE
is probably more accurate and easier to grasp than "scalar logical"
R/detect.R
Outdated
@@ -51,7 +51,7 @@ detect <- function(.x, .f, ..., .right = FALSE) { | |||
#' @export | |||
#' @rdname detect | |||
detect_index <- function(.x, .f, ..., .right = FALSE) { | |||
.f <- as_mapper(.f, ...) | |||
.f <- as_predicate(.f, ..., .mapper = TRUE) | |||
|
|||
for (i in index(.x, .right)) { | |||
if (is_true(.f(.x[[i]], ...))) return(i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can now remove the is_true()
?
lionel-
force-pushed
the
fix-predicate-warning
branch
from
November 30, 2018 14:48
0e9b4d6
to
f9ff267
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #470.
keep()
,map_if()
, and variants now fail with an informative error message when the predicate function dose not returnTRUE
orFALSE
.This is only soft-deprecated for
every()
andsome()
as they were documented to have liberal truthness. Also the unit tests check that these functions returnNA
when the predicate has returnedNA
. I think it's best to deprecate this behaviour for consistency with predicate-based functionals within purrr, and because it simplifies the type of these functions (you can count on them returning TRUE/FALSE, missing values have to be dealt beforehand to avoid an early error).