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

Using modify_at() for removing elements #716

Closed
echasnovski opened this issue Oct 26, 2019 · 2 comments
Closed

Using modify_at() for removing elements #716

echasnovski opened this issue Oct 26, 2019 · 2 comments
Labels
feature a feature request or enhancement

Comments

@echasnovski
Copy link

Recently on Twitter there was a discussion about a tidy way of removing vector elements given their names (this tweet in particular).
I suggested modify_at(x, names_to_remove, ~NULL), but it failed to work with multiple elements (thanks to this tweet from EFromTheWest user):

x <- list(a = 10, b = 15, c = 18, d = 9)
names_to_drop <- c("a", "b", "c")
purrr::modify_at(x, names_to_drop, ~NULL)
#> $b
#> [1] 15
#> 
#> $d
#> [1] 9

Created on 2019-10-26 by the reprex package (v0.3.0)

This seems to be because internally modify_at() uses modify_if(), which in turn is implemented with iterative modification based on integer indexes (see these lines). This approach fails to work if elements are removed as a result of modification.

This issue is created to notify about this possible confusion and, probably, for you to consider supporting this behavior.

@lionel-
Copy link
Member

lionel- commented Jan 20, 2020

We could support this via rlang::zap(). However I'm not sure that we should allow the result of modify_ functions to have a different size than the output.

@lionel- lionel- added the feature a feature request or enhancement label Jan 20, 2020
@hadley
Copy link
Member

hadley commented Aug 24, 2022

We're generally going to move away from the _at() functions (#874) which means that we won't be adding any new features to them.

@hadley hadley closed this as completed Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants