Source Code R. Call Function

I looked at the cov source code in R and came across a paragraph of code that I don't quite understand.

The mathematical definition of covariance is given below .

if (method == "pearson") .Call(C_cov, x, y, na.method, method == "kendall") else if ... 

The reference guide talks about the .Call function:

 CallExternal {base} R Documentation Modern Interfaces to C/C++ code Description Functions to pass R objects to compiled C/C++ code that has been loaded into R. 

I am wondering where I can find the source code for calculating the covariance of C ++ or C or something else.

Thanks.

+7
r
source share
1 answer

.Call used to pass variables to C. subroutines. C_cov is a variable (in the stats namespace that we will see soon) that tells .Call where to find the subroutine that it should use to calculate covariance.

If you type C_cov at the command line, you will get

 Error: object 'C_cov' not found 

This is because it is hidden from you. You will need to do a little detective work.

 getAnywhere('C_cov') # 4 differing objects matching 'C_cov' were found # in the following places # namespace:stats # Use [] to view one of them 

This tells us that in the stats namespace there is a variable called C_cov (your result may be slightly different from this). Let's try to get it.

 stats::C_cov # Error: 'C_cov' is not an exported object from 'namespace:stats' 

Apparently C_cov not intended for public consumption. Everything is in order, we still get:

 stats:::C_cov # use three colons to get unexported variables. # $name # [1] "cov" # # blah, blah, blah ... # $dll # DLL name: stats # Filename: C:/Program Files/R/R-3.0.1/library/stats/libs/x64/stats.dll # Dynamic lookup: FALSE # # blah, blah, ... 

What we want. He tells us the name of the subroutine and library. Now we just need to go to the C source and follow the trail: ... / src / library / stats / src / cov.c

+12
source share

All Articles