4

I'm new to R. I noticed that the acf function of R makes this call:

acf <- .Call(C_acf, x, lag.max, type == "correlation")

I want to find the C_acf function in the c library, and perhaps modify it. Anyone knows how I can find the C_acf function? which C code is it written in? I can even how its modified version be called locally, but I want to know what the C version is doing under the hood.

user1871528
  • 1,655
  • 3
  • 27
  • 41
  • See the 3rd paragraph under the section, "Functions that call compiled code". – Joshua Ulrich Dec 29 '14 at 00:51
  • Josh where can I find ""Functions that call compiled code".... not sure what you are referring to – user1871528 Jan 02 '15 at 04:54
  • I see that Josh. I'm not asking what the R codes for the function is I'm asking what this line means: .Call(C_acf, x, lag.max, type == "correlation")... my understanding is that it is calling the C_acf function which is a C compiled code. The main question is where is the C_acf function located at thats what I was hoping someone could answer because I can't find it. – user1871528 Jan 02 '15 at 05:03
  • the answer is filter.c... obviously I cant answer my own questions since its been duplicated – user1871528 Jan 02 '15 at 05:49
  • It's "been duplicated" because it *is* a duplicate of the marked question. The answer to the marked question does not only describe how to find the R code for the function. It tells you how to locate the C/Fortan source code as well. The meaning of `.Call(C_acf, x, lag.max, type == "correlation")` is described in the marked answer, in the section, "Functions that call compiled code". How to find the location of the function described by the `C_acf` *object* is described in the section, "Compiled code in a base package". – Joshua Ulrich Jan 02 '15 at 13:05
  • 1
    Again that questions gives you a general overview and not how to search through R. The answer either had to tell me the file name, the rep i should look into, shed some light. the answer you gave just said look inside the download R source code..... I could had told you that before I knew programming.... not insightful – user1871528 Jan 04 '15 at 01:25
  • Of course it gives a general overview. How to find the source for one specific function would be of no use to anyone who was looking for the source of any other function. The answer tells you which directories to look in the R sources (for both built-in functions and base packages), and provides a coulple web interfaces you can use. If you don't know how to search files for text, that's outside the scope of the question. If you think the answer to the linked question is lacking, suggest an edit. – Joshua Ulrich Jan 04 '15 at 06:07
  • I was actually searching for the location of this function, and couldn't find it in the R source code. Turns out a fast way to search text is to Google it, and when Googling programming questions, often one can land here. Now I know I can look for the function `C_acf` in the file `filter.c` – definitely not duplicated information from my perspective (though I see your point); thanks @user1871528 – rbatt May 12 '15 at 20:54
  • @JoshuaUlrich I don't have a computer background, and got lost following the more general CW answer linked by you in the OP. The RNews_2006 article didn't help me, either. I wonder if you could somehow provide the answer to this specific question, perhaps as an example in the CW answer? – Antoni Parellada Jan 03 '17 at 01:26
  • @Toni: I don't have a computer background either ;). The 3rd paragraph under the section "Functions that call compiled code" in the CW answer tells you how to get information about the compiled function, since `C_acf` is an object, not a character string. Printing `C_acf` tells you the C function name is "acf". Now you can use the instructions in the "Compiled code in a base package" section. Or you can go to the [GitHub mirror](https://github.com/wch/r-source/) and search for "acf" in C files. The first hit is `filter.c`, which contains the `acf` definition. – Joshua Ulrich Jan 03 '17 at 15:52
  • @JoshuaUlrich Thank you. I am not clear on how this works, but I got the answer to how `acf()` works [here](http://stats.stackexchange.com/questions/254227/manual-calculation-of-acf-of-a-time-series-in-r-close-but-not-quite). – Antoni Parellada Jan 03 '17 at 17:12

0 Answers0