简体   繁体   中英

R chain operator usage

I understood that in R we can create special function by using chain operator, but how can I know the function implementation/code for the chain operator?

If I want to find out source for a function, I use > functionname

But when I tried to find source code for operator > "%*%" it didn't print anything. Could someone please help me how I can find out source code for above chain operator?

Assuming you are talking about the pipe operator, you need to have the package magrittr loaded or dplyr loaded using library . Then you need to use backticks to access the function definition:

library(dplyr)
`%>%`

which gives

function (lhs, rhs)     {
    lhs <- substitute(lhs)
    rhs <- substitute(rhs)
    if (is.call(rhs) && identical(rhs[[1]], quote(`(`))) 
        rhs <- eval(rhs, parent.frame(), parent.frame())
    ...

The reason for this is explained here Function name in single quotation marks in R

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM