How to find out which .c file contains the .c functions of R internals, on Windows?

As a Windows user, here are a couple of options. The first one is preferable, but the second one is OK for occasional use:

  • Download grepwin, which will allow you to search Windows directories using the powerful grep command that both Joshua and Gavin have mentioned. It (or some equivalent) is indispensable if you'll be doing much poking around in program source directories.

  • Use the search bar at this site to search the R source directory for the definition of do_matchcall. Clicking on the result it returns will tell you that do_matchcall is "[defined] at line 1193 of file unique.c", and will provide a hyperlink to the code in unique.c.

Like I said, though, you'll ultimately be much happier if you equip your Windows box with some implementation of grep.


I know this has been asked a long time ago, but since it's still relevant, I thought I'd add some resources people can use to find the proper R source files.

  1. First, with pryr you can use the show_c_source function which will search on GitHub the relevant piece of code in the C source files.

    body(match.call)
    
    # .Internal(match.call(definition, call, expand.dots))
    
    pryr::show_c_source(.Internal(match.call(definition, call, expand.dots)))
    

    Which takes you to this page, showing that unique.c contains the function do_matchcall.

  2. I've put together this tab delimited file, building on the names.c file and using find-in-files to determine the location of the source code. There are some functions that have platform-specific files, and a handful of others for which there is more than one file with relevant source code. But for the rest the mapping is pretty well established, at least for the current version (3.1.2).


Uwe Ligges wrote an "R Help Desk" article on this very topic in R News (2006, 6(4):43-45).

Once you've identified the actual C function that is used, then use your filesystem search tools to search for the function name in the relevant source folder; in this case ./src/main/, e.g. on Linux

$ grep -r -H "do_matchcall" ./src/main/
./src/main/.svn/text-base/names.c.svn-base:{"match.call",   do_matchcall,   0,  11, 3,  {PP_FUNCALL, PREC_FN,   0}},
./src/main/.svn/text-base/unique.c.svn-base:SEXP attribute_hidden do_matchcall(SEXP call, SEXP op, SEXP args, SEXP env)
./src/main/unique.c:SEXP attribute_hidden do_matchcall(SEXP call, SEXP op, SEXP args, SEXP env)
./src/main/names.c:{"match.call",   do_matchcall,   0,  11, 3,  {PP_FUNCALL, PREC_FN,   0}},

indicating that unique.c is the place to look in this case.

To the best of my knowledge, there is no way (other than invoking a system call to the terminal) to identify from within R which source file contains the C code for a given function in R - well, not without rewriting grep or find or similar using R code :-)