←
PDF 293 / 520 are some other useful tools inside magrittr that you might want to try out:
→
English · PDF 293
Original PDF page 293
中文 · PDF 293

magrittr 中还有一些其他有用的工具,你可能会想尝试一下:

  • 在使用更复杂的管道时,有时为了函数的副作用而调用它会很有用。也许你想打印出当前对象,或者绘制它,或者将它保存到磁盘。很多时候,这类函数不返回任何内容,实际上会终止管道。

为了解决这个问题,你可以使用 "tee" 管道。%T>% 的作用类似于 %>%,区别在于它返回的是左侧而不是右侧的结果。它被称为 "tee",因为它就像一个字面意义上的 T 形管道:

rnorm(100) %>% matrix(ncol = 2) %>% plot() %>% str() #> NULL

rnorm(100) %>% matrix(ncol = 2) %T>% plot() %>% str() #> num [1:50, 1:2] -0.387 -0.785 -1.057 -0.796 -1.756 ...