我想知道如何在dplyr链中存在条件元素的情况下使用基本的|>
管道代替tidyverse的%>%
。当我尝试使用|>
运行以下代码时,会出现错误:
Error: function '{' not supported in RHS call of a pipe
使用Tidyverse的示例
library(tidyverse)
condition = FALSE
mtcars %>%
{ if(condition == TRUE)
mutate(., mpg = mpg*1000)
else . }
使用基本的R管道的示例(会导致错误):
mtcars |>
{ if(condition == TRUE)
mutate(., mpg = mpg*1000)
else . }