-
Notifications
You must be signed in to change notification settings - Fork 275
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
Changes list_modify to be able to remove key-value pairs whose value is a list #777
Changes list_modify to be able to remove key-value pairs whose value is a list #777
Conversation
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.
Looks good, can you just remove the extra whitespace changes please?
The documentation to list_modify indicates that one should "[u]se zap() to remove values" from a list. This does not work in the expected way when attempting to remove a key-value pair whose value is a list: ```r library(purrr) list(foo = 1, bar = 2) %>% list_modify(foo = zap()) list(foo = c(1, 2), bar = 3) %>% list_modify(foo = zap()) list(foo = list(fst = 1, snd = 2), bar = 3) %>% list_modify(foo = zap()) ``` The first two examples above return an object identical to list(bar = 3); the third is such that the call to list_modify is a no-op. This commit fixes this behaviour. This commit also adds some further whitespace. Issues: #776
This commit adds a unit test for list_modify to check that it can correctly remove key-value pairs whose value is a list. Issues: #776
I've removed the whitespace changes (but it's a little unclear whether I need to re-raise the request; this is the first time I've opened a (real) PR in GitHub, so please let me know if I've done something wrong). I'm quite happy to contribute more of my time to purrr (and the tidyverse more broadly)—is there a register of issues, or something similar? |
No need to reopen the pull request as this would just add noise. Pushing the changes directly in the pull request is the way to go. You also need to add a NEWS bullet explaining your change and linking to your github handle and the relevant github issue. I've done that now.
We sometimes have "help wanted" or "good first contribution" labels on github issues. Thanks for the fix! |
I would like to recommend an additional test that fails on the current release but should be fixed by this patch: expect_equal(list_modify(list(list(1,2), 2, 3), zap(), zap()), list(3)) This test exercises the branch of code which is used for replacing a list when the arguments are not named. It parallels the added test in this pull request for named arguments. |
The documentation to
list_modify
indicates that one should "[u]sezap()
to remove values" from a list. This does not work in the expected way when attempting to remove a key-value pair whose value is a list:The first two examples above return an object identical to
list(bar = 3)
; the third is such that the call tolist_modify
is a no-op. This pull request fixes this behaviour. It also adds a unit test to cover this case.Issues: #776