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.

4
  • you need the cpp/h files Commented Aug 21, 2013 at 2:45
  • C and C++ are both compiled languages, if you have the source from which it was compiled then you can get the definitions, otherwise you are out of luck. Commented Aug 21, 2013 at 2:46
  • @JoshuaUlrich My question seems like an exact duplicate of the question linked. Should I delete this question? Commented Aug 21, 2013 at 3:00
  • I think this question is useful because it rephrases the question linked. So, the answer might be same but rephrasing the question to have C/C++ or lapply is beneficial in my opinion. Commented Aug 21, 2013 at 7:31

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

You can also Google search the svn repository directly using site:https://svn.r-project.org/R/ and your desired terms.
@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++.
That's easily done with Google by specifying filetype:c.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.