I am trying to study the detailed code behind certain functions in igraph
package in R.
For example in the code chunk below I wanted to see the function behind fast greedy clustering. igraph::cluster_fast_greedy
shows the R function. It, in turn, calls on certain functions written in C, most importantly C_R_igraph_community_fastgreedy
. It is clear that the following code does not do the clustering directly but calls the aforementioned C function. I want to know how to view and edit those.
I know that using trace()
would allow me to edit the R function.
> igraph::cluster_fast_greedy
function (graph, merges = TRUE, modularity = TRUE, membership = TRUE,
weights = E(graph)$weight)
{
if (!is_igraph(graph)) {
stop("Not a graph object")
}
if (!is.null(weights)) {
weights <- as.numeric(weights)
}
on.exit(.Call(C_R_igraph_finalizer))
res <- .Call(C_R_igraph_community_fastgreedy, graph, as.logical(merges),
as.logical(modularity), as.logical(membership), weights)
if (igraph_opt("add.vertex.names") && is_named(graph)) {
res$names <- V(graph)$name
}
res$algorithm <- "fast greedy"
res$vcount <- vcount(graph)
res$membership <- res$membership + 1
res$merges <- res$merges + 1
class(res) <- "communities"
res
}
<bytecode: 0x000001d95fb78be0>
<environment: namespace:igraph>
I am posting this question at the risk of being marked duplicate, but the answers to previous similar questions have not been of much help to me. They can be found here and here.
I have checked the folder where igraph
is downloaded in my computer and did not find any such file that seemed relatable.
I have also looked at their github.
C
code for R
packages are found inside the src/
folder:
src folder of igraph.
In your case, the function is here.