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

Feature request: allow variable as the end of a chain #2433

Closed
tmalsburg opened this issue Feb 18, 2017 · 2 comments
Closed

Feature request: allow variable as the end of a chain #2433

tmalsburg opened this issue Feb 18, 2017 · 2 comments

Comments

@tmalsburg
Copy link

tmalsburg commented Feb 18, 2017

It would be convenient to be able to pipe the results of a processing chain into a variable as in the following example:

mtcars %>%
  filter(mpg > median(mpg)) %>%
  efficient.cars

Currently this produces an error (could not find function "efficient.cars") but I think it would be very useful if we were able to do this. There is a simple fix,

mtcars %>%
  filter(mpg > median(mpg)) ->
  efficient.cars

but this means that I often have to switch -> and %>% during development (every time, the last step in a chain changes) and this creates unnecessary friction.

I think it would be logically consistent to allow piping into a variable since we also can pipe from a variable. Thanks for considering this and sorry if this has been discussed previously.

@tmalsburg tmalsburg changed the title Feature request: allow variable name at the end of a chain Feature request: allow variable at the end of a chain Feb 18, 2017
@tmalsburg tmalsburg changed the title Feature request: allow variable at the end of a chain Feature request: allow variable as the end of a chain Feb 18, 2017
@tmalsburg
Copy link
Author

@klmr
Copy link

klmr commented Feb 20, 2017

I think this belongs in magrittr not dplyr. At any rate it isn’t currently possible because of the reason stated in the error message: if the last identifier in a pipe chain is a name, it’s interpreted as a function name. That is, … %>% foo is equivalent to … %>% foo().

@hadley hadley closed this as completed Feb 20, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants