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

后端 未结 4 404
南方客
南方客 2020-12-10 03:06

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

相关标签:
4条回答
  • 2020-12-10 03:45

    Don't download a utility for a one time file content search. You can use findstr. It isn't suitable for a full file system search, but I think it's perfect for what you are trying to do.

    1. run the command shell

    cmd

    1. go to the directory (if you are not sure what the path is, find it in explorer than view the full path by clicking in the address bar) You can copy/paste that directory.
      If the path is C:\Users\jsmith\documents\projects\happy\src\main

    cd C:\Users\jsmith\documents\projects\happy\src\main

    1. use findstr

    findstr do_matchcall

    if you want to search sub directories

    findstr /s do_matchcall

    if only want to know the filename

    findstr /m do_matchcall

    if you want to send the results to another file

    findstr /s /m do__matchcall >searchresult.txt

    if you want the line numbers

    findstr /n do_matchcall

    Findstr also supports regular expressions. To see all the options

    findstr /?

    0 讨论(0)
  • 2020-12-10 03:53

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

    0 讨论(0)
  • 2020-12-10 03:58

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

    0 讨论(0)
  • 2020-12-10 04:00

    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.

    0 讨论(0)
提交回复
热议问题