I'm trying to take a peak under the hood of the base r function kmeans but I can't seem to find the source code for some of the underlying functions. Namely:
The fortran function "C_kmns"
The C functions : C_kmens_Lloyd and C_kmeans_MacQueen
How/where should I look for the code of these functions?
> getAnywhere(C_kmeans_Lloyd)
A single object matching ‘C_kmeans_Lloyd’ was found
It was found in the following places
namespace:stats
with value
$name
[1] "kmeans_Lloyd"
$address
<pointer: 0x0000024ae68344a0>
attr(,"class")
[1] "RegisteredNativeSymbol"
$dll
DLL name: stats
Filename: C:/Program Files/R/R-3.6.2/library/stats/libs/x64/stats.dll
Dynamic lookup: FALSE
$numParameters
[1] 9
attr(,"class")
[1] "CRoutine" "NativeSymbolInfo"
my interpretation is that we are only provided a compiled routine that lives in the stats.dll
I suppose you can try to contact the R foundation for such details ? https://www.r-project.org/foundation/
Is this the one you mean? It's actually in Fortran, but inspection of the output of getAnywhere(kmeans) indicates that kmns is a Fortran function (see the line Z <- .Fortran(C_kmns, x, m, p, centers = centers,).
I found it by going to the R source code mirror on github and typing kmns in the search box. If you scroll down through the results, you'll see a file called kmns.f, which is the one linked above.