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

Allow modify() to modify calls #412

Closed
hadley opened this issue Nov 14, 2017 · 2 comments
Closed

Allow modify() to modify calls #412

hadley opened this issue Nov 14, 2017 · 2 comments

Comments

@hadley
Copy link
Member

hadley commented Nov 14, 2017

library(rlang)
library(purrr)

x <- expr(foo(a, b, 10))
modify(x, ~ if (is.numeric(.x)) .x + 10 else .x)

We should probably expand the vector definition to include pairlists (this will require custom code but it's probably worth it as the connections between purrr and rlang become stronger)

@hadley
Copy link
Member Author

hadley commented Nov 20, 2017

For map(), this will require a different approach to map_impl() + call_loop() which currently generates calls of the form f(x[[i]]) modifying the value of i in an environment. Instead will need to generate __x_i by looping over the pairlist. For efficiently, will also need to name output as we go using the TAG().

May also be worth a custom modify() method because replacement with [[<- is unlikely to be efficient.

In the short term, might be better to just coerce back and forth to a list, not worrying about efficiency.

@hadley
Copy link
Member Author

hadley commented Nov 20, 2017

Actually we can just rely on the fact that [[ has an existing implementation

@hadley hadley closed this as completed in 1caf625 Nov 20, 2017
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

No branches or pull requests

1 participant