Skip to content
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

Merged
merged 3 commits into from Jul 31, 2020
Merged

Changes list_modify to be able to remove key-value pairs whose value is a list #777

merged 3 commits into from Jul 31, 2020

Conversation

adamroyjones
Copy link
Contributor

@adamroyjones adamroyjones commented Jul 10, 2020

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:

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 pull request fixes this behaviour. It also adds a unit test to cover this case.

Issues: #776

@adamroyjones adamroyjones changed the title #776: Changes list_modify to remove key-value pairs whose value is a list Changes list_modify to remove key-value pairs whose value is a list Jul 10, 2020
@adamroyjones adamroyjones changed the title Changes list_modify to remove key-value pairs whose value is a list Changes list_modify to be able to remove key-value pairs whose value is a list Jul 11, 2020
Copy link
Member

@lionel- lionel- left a 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
@adamroyjones
Copy link
Contributor Author

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?

@lionel- lionel- merged commit 983c0f8 into tidyverse:master Jul 31, 2020
@lionel-
Copy link
Member

lionel- commented Jul 31, 2020

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.

is there a register of issues, or something similar?

We sometimes have "help wanted" or "good first contribution" labels on github issues.

Thanks for the fix!

@BrianDiggs
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants