对于magrittr管道,可以使用反引号 (`)在管道链中包含特殊功能1。例如:
library(magrittr)
c(7, 6, 5) %>% sort() %>% `[`(1)
#> [1] 5
# and
3 %>% `-`(4)
#> [1] -1
Run Code Online (Sandbox Code Playgroud)
是一样的
v <- c(7, 6, 5)
v <- sort(v)
v[1]
#> [1] 5
# and
3 - 4
#> [1] -1
Run Code Online (Sandbox Code Playgroud)
但是,本机 R 管道|>(还?)不允许这样做。例如:
c(7, 6, 5) |> sort() |> `[`(1)
#> Error: function '[' not supported in RHS call of a pipe
# and
3 |> `-`(4)
#> Error: function '-' not …Run Code Online (Sandbox Code Playgroud)