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

Deprecation of when: can documentation show the equivalent code to previous when() use? #1059

Closed
MatthieuStigler opened this issue Feb 24, 2023 · 3 comments

Comments

@MatthieuStigler
Copy link

A convenient use of when() was as a conditional pipe, as was shown in the example, and as was advocated on Stack (R Conditional evaluation when using the pipe operator %>%).

Unfortunately, with the deprecation of when() in purrr 1.0.0, while the documentation mentions that one should use if instead, the replacement example does does not correspond to the previous example, where when was used as conditional pipe? Could the documentation seek to provide an equivalent code suggestion?

Thanks!

@steffen-stell
Copy link

Can you provide an example where this does not work? The example in the answer advocating the use of when() is:

1:3 %>% 
  purrr::when(sum(.) < 25 ~ sum(.), ~0)

and can easily be replaced with

1:3 %>%
  {if (sum(.) < 25) sum(.) else 0}

@MatthieuStigler
Copy link
Author

thanks @steffen-stell
My point was not about code "working" but the recommended alternative/best practice being documented. Unfortunately, the current documentation does not provide an equivalent code example for what I believe was a common use of when

@hadley
Copy link
Member

hadley commented Jul 26, 2023

I don't think there currently is a good alternative for that very specific use case. In my opinion, once you start adding branching to a pipe, you're starting to make a pipe that's going to be hard for other people to understand.

@hadley hadley closed this as completed Jul 26, 2023
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

3 participants