1

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?

kosa
  • 65,990
  • 13
  • 130
  • 167

1 Answers1

0

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

Community
  • 1
  • 1
Alex
  • 15,186
  • 15
  • 73
  • 127
  • Thank you for the answer! No, I am talking about * operator. How can I find source for %*% – kosa Oct 07 '14 at 20:42
  • 1
    @Nambari You can use: ` `%*%` ` which returns: ``unction (x, y) .Primitive("%*%")` – DatamineR Oct 07 '14 at 20:49
  • Ok, When I used back tick, it gave me .Primitive("%*%"), now I need to figure out how can I find out source for these primitive functions. Thanks! – kosa Oct 07 '14 at 20:49
  • @RStudent: thanks! it seems we both posted comment almost same time. – kosa Oct 07 '14 at 20:50
  • Ok, I think I figured it out, it is do_matprod function call. – kosa Oct 07 '14 at 21:04
  • 1
    This [question](http://stackoverflow.com/questions/14035506/how-to-see-the-source-code-of-r-internal-or-primitive-function) can give a few hints. Here is a search in R source looking for [do_matprod](https://github.com/wch/r-source/search?utf8=%E2%9C%93&q=do_matprod&type=Code). You seem to be rigth. – marbel Oct 07 '14 at 21:27