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

Native pipe does not work with rowwise #6965

Closed
Yann-C-INN opened this issue Nov 14, 2023 · 6 comments
Closed

Native pipe does not work with rowwise #6965

Yann-C-INN opened this issue Nov 14, 2023 · 6 comments

Comments

@Yann-C-INN
Copy link

Yann-C-INN commented Nov 14, 2023

Using the dplyr::rowwise i noticed something strange.
The native R pipe (|>) Doesn't work, where's the magrittr::%>% works just fine.

The following code works:

mtcars |> rowwise() %>% mutate(sum = sum(.))

But this one doesnt:

mtcars |> rowwise() |> mutate(sum = sum(.))

@bhattmaulik
Copy link

I guess the problem is not the pipe, but the dot inside sum(.). The base R pipe needs a different syntax to work.

@Yann-C-INN
Copy link
Author

Yann-C-INN commented Nov 14, 2023

I guess the problem is not the pipe, but the dot inside sum(.). The base R pipe needs a different syntax to work.

It doesnt make sensethat these pipes will not work the same... I find this a bugrather than a feature.

For my own purpose I already solved it (My use case was a bit more complex obviously), but it doesnt resonate with me that they would behave differently.

@philibe
Copy link

philibe commented Nov 14, 2023

It doesnt make sensethat these pipes will not work the same... I find this a bugrather than a feature.

I think you're wrong :)

They are similar but intrinsically a little different.

Read that please:

edit: the Stackoverflow answer added

@philibe
Copy link

philibe commented Nov 14, 2023

Here is a workaround for an identical result to your example mtcars |> rowwise() %>% mutate(sum = sum(.))

@Yann-C-INN
Copy link
Author

Here is workaround for result identical to your example mtcars |> rowwise() %>% mutate(sum = sum(.))

the workaround is to use the more robust pipe if you ask me ;) thanks though. I am not convinced that this is something worth keeping in the future (the differences) but sure. I'll adjust my defaults

@DavisVaughan
Copy link
Member

The base R pipe is deliberately different from the magrittr pipe. The differences are outlined in https://www.tidyverse.org/blog/2023/04/base-vs-magrittr-pipe/#-vs as @philibe mentioned, and there is nothing dplyr can do to support this differently

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

4 participants