Closed MatthieuStigler closed 1 year ago
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}
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
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.
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 useif
instead, the replacement example does does not correspond to the previous example, wherewhen
was used as conditional pipe? Could the documentation seek to provide an equivalent code suggestion?Thanks!