how to feed the result of a pipe chain (magrittr) to an object

后端 未结 5 467
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-31 19:02

This is a fairly simply question. But I couldn\'t find the answer per google/stackexchange and looking at the documentation of magrittr. How do you feed the result of a chain of

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-31 19:25

    You can do it like so:

    data.frame( x = c(1:3), y = (4:6)) %>%  
    sum %>%  
    assign(x="a",value=.,pos=1)  
    

    A couple of things to note:

    You can use "." to tell magrittr which argument the object being brought forward belongs in. By default it is the first, but here I use the . to indicate that I want it in the second value argument instead.

    Second I had to use the pos=1 argument to make the assignment in the global environment.

提交回复
热议问题