Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I want to view the source code of R's match.call function. As it is an internal function, I downloaded the R source code, went to ./src/main/names.c and looked for match.call there.

Thus, I found out that the corresponding .c function is called do_matchcall. Ok, but how can I find out which of the dozens of .c files in ./src/main/ contains the function do_matchcall?

Btw I'm using a Windows machine, in case that makes a difference.

like image 883
Wolfgang Pößnecker Avatar asked Nov 07 '12 22:11

Wolfgang Pößnecker


People also ask

How do you call C from R?

Calling C functions from R Call is to use . External . It is used almost identically, except that the C function will receive a single argument containing a LISTSXP , a pairlist from which the arguments can be extracted. This makes it possible to write functions that take a variable number of arguments.

What is internal R?

Internal resistance refers to the opposition to the flow of current offered by the cells and batteries themselves resulting in the generation of heat. Internal resistance is measured in Ohms. The relationship between internal resistance (r) and emf (e) of cell s given by.


2 Answers

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.

like image 79
Josh O'Brien Avatar answered Sep 27 '22 18:09

Josh O'Brien


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).

like image 32
Dominic Comtois Avatar answered Sep 27 '22 19:09

Dominic Comtois