I am wondering how to use the base |> pipe in place of tidyverse's %>% in a situation where there are conditional elements of a dplyr chain. When I try to following code with |>, I get an error:
Error: function '{' not supported in RHS call of a pipe
Example with Tidyverse
library(tidyverse)
condition = FALSE
mtcars %>%
{ if(condition == TRUE)
mutate(., mpg = mpg*1000)
else . }
Example with base R pipe (causes error):
mtcars |>
{ if(condition == TRUE)
mutate(., mpg = mpg*1000)
else . }