4

In general, the source code for functions written in R can be looked up just by typing the name of the function on R console. How do you do it for functions which are written in C or C++?

For e.g. when I try and look up the code for lapply() function, it shows me this -

function (X, FUN, ...) 
{
    FUN <- match.fun(FUN)
    if (!is.vector(X) || is.object(X)) 
        X <- as.list(X)
    .Internal(lapply(X, FUN))
}
<bytecode: 0x0000000007384128>
<environment: namespace:base>

which doesn't help in anyways to understand what exactly this function is doing.

steadyfish
  • 847
  • 2
  • 12
  • 27

1 Answers1

2

You can search for lapply or any other function in this mirror of R source repository: https://github.com/wch/r-source

Then choose C/C++ from the languages in the left to get to this page: https://github.com/wch/r-source/search?l=c&q=lapply&ref=cmdform

kaisernahid
  • 341
  • 2
  • 13
  • 3
    You can also Google search the svn repository directly using `site:https://svn.r-project.org/R/` and your desired terms. – thelatemail Aug 21 '13 at 04:12
  • @thelatemail, yes, but github repository is advantageous over 'site' search in Google as github will allow you to specify C/C++ file too. In our example, there are over 150 R files referring to lapply but only 9 referring to C/C++. – kaisernahid Aug 21 '13 at 07:27
  • That's easily done with Google by specifying `filetype:c`. – Joshua Ulrich Aug 21 '13 at 10:30