Skip to content
Draft
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3a9ed79
Initial plan
Copilot Jan 27, 2026
3937dfc
Add comments explaining why .Call() expressions cannot be replaced wi…
Copilot Jan 27, 2026
a85a698
Fix syntax error in attributes.R comment placement
Copilot Jan 27, 2026
330f326
Replace .Call() with _impl functions where possible, add explanatory …
Copilot Jan 27, 2026
5c6041f
Replace subcomponent, girth, ego_size, ego, make_ego_graph with _impl…
Copilot Jan 27, 2026
483a118
Add comments to remaining .Call() expressions in structural-properties.R
Copilot Jan 27, 2026
08ff3d5
Add comment explaining efficiency trade-off in girth() using girth_im…
Copilot Jan 27, 2026
86f4d82
Update BFS/DFS comments to reference bfs_closure_impl/dfs_closure_impl
Copilot Jan 27, 2026
d2302de
Add comments to internal .Call() expressions in attributes.R
Copilot Jan 27, 2026
05fcfa1
Add comments and replacements for .Call() in bipartite.R, centrality.…
Copilot Jan 27, 2026
085591d
Add comments to all remaining .Call() expressions across R files
Copilot Jan 27, 2026
d7c4ce7
Replace .Call() with _impl functions in layout, interface, foreign fi…
Copilot Jan 27, 2026
c4ab986
Fix layout functions to properly initialize coords when NULL before c…
Copilot Jan 27, 2026
31579a3
Fix weight handling in layout functions to let _impl handle defaults
Copilot Jan 27, 2026
a524504
Revert some foreign.R functions to .Call() due to _impl bugs or diffe…
Copilot Jan 27, 2026
474b71e
Replace more .Call() with _impl functions: count_components, count_ma…
Copilot Jan 30, 2026
1dc318e
Add igraph API comments to remaining .Call() expressions
Copilot Jan 30, 2026
4f103aa
Remove errant snapshot file
Copilot Jan 30, 2026
318a0f5
Add detailed igraph API function names to remaining .Call() comments
Copilot Jan 30, 2026
366a715
Fix type comparison bug in bipartite_projection warning
Copilot Jan 30, 2026
0d52819
Add igraph API function names to .Call() comments; replace spinglass …
Copilot Jan 30, 2026
ef518a7
Merge branch 'main' into copilot/replace-call-expressions-with-impl-f…
krlmlr Apr 12, 2026
4c302a8
chore: Auto-update from GitHub Actions
krlmlr Apr 12, 2026
3fa66f7
Improve .Call() comments with specific igraph API function names
Copilot Apr 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 36 additions & 80 deletions R/structural-properties.R
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ diameter <- function(
}

on.exit(.Call(Rx_igraph_finalizer))
.Call(
.Call( # diameter_impl returns more info (path); uses Dijkstra for weighted
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which igraph_* API is called by the Rx_ function?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 0d52819: Rx_igraph_diameter calls igraph_diameter_dijkstra(). The diameter_impl returns path info too.

Rx_igraph_diameter,
graph,
as.logical(directed),
Expand Down Expand Up @@ -797,7 +797,7 @@ get_diameter <- function(
}

on.exit(.Call(Rx_igraph_finalizer))
res <- .Call(
res <- .Call( # diameter_impl returns more info (path)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which igraph_* API is called by the Rx_ function? Can we apply postprocessing here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 0d52819: Rx_igraph_get_diameter calls igraph_diameter_dijkstra(). The diameter_impl returns path info too. Could apply postprocessing to extract just the path.

Rx_igraph_get_diameter,
graph,
as.logical(directed),
Expand Down Expand Up @@ -833,7 +833,7 @@ farthest_vertices <- function(
}

on.exit(.Call(Rx_igraph_finalizer))
res <- .Call(
res <- .Call( # no farthest_vertices_impl available
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which igraph_* API is called by the Rx_ function?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 0d52819: Rx_igraph_farthest_points calls igraph_diameter_dijkstra(). No farthest_vertices_impl available.

Rx_igraph_farthest_points,
graph,
as.logical(directed),
Expand Down Expand Up @@ -1245,7 +1245,7 @@ distances <- function(
}

on.exit(.Call(Rx_igraph_finalizer))
res <- .Call(
res <- .Call( # distances_impl doesn't support algorithm selection
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which igraph_* API is called by the Rx_ function?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 0d52819: Rx_igraph_shortest_paths calls multiple igraph_distances*() functions depending on algorithm. The distances_impl doesn't support algorithm selection.

Rx_igraph_shortest_paths,
graph,
v - 1,
Expand Down Expand Up @@ -1329,7 +1329,7 @@ shortest_paths <- function(

to <- as_igraph_vs(graph, to) - 1
on.exit(.Call(Rx_igraph_finalizer))
res <- .Call(
res <- .Call( # get_shortest_paths_impl doesn't support algorithm selection
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which igraph_* API is called by the Rx_ function?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 0d52819: Rx_igraph_get_shortest_paths calls multiple igraph_get_shortest_paths*() functions. The _impl doesn't support algorithm selection.

Rx_igraph_get_shortest_paths,
graph,
as_igraph_vs(graph, from) - 1,
Expand Down Expand Up @@ -1522,24 +1522,11 @@ k_shortest_paths <- function(
#' subcomponent(g, 1, "out")
#' subcomponent(g, 1, "all")
subcomponent <- function(graph, v, mode = c("all", "out", "in")) {
ensure_igraph(graph)
mode <- igraph_match_arg(mode)
mode <- switch(mode, "out" = 1, "in" = 2, "all" = 3)

on.exit(.Call(Rx_igraph_finalizer))
res <- .Call(
Rx_igraph_subcomponent,
graph,
as_igraph_vs(graph, v) - 1,
as.numeric(mode)
) +
1L

if (igraph_opt("return.vs.es")) {
res <- create_vs(graph, res)
}

res
subcomponent_impl(
graph = graph,
vid = v,
mode = mode
)
}

#' Subgraph of a graph
Expand Down Expand Up @@ -1822,7 +1809,7 @@ transitivity <- function(
} else if (type == 1) {
isolates_num <- as.double(switch(isolates, "nan" = 0, "zero" = 1))
if (is.null(vids)) {
res <- .Call(
res <- .Call( # transitivity_local_undirected_impl requires vids
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which igraph_* API is called by the Rx_ function?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 0d52819: Rx_igraph_transitivity_local_undirected_all calls igraph_transitivity_local_undirected(). The _impl requires vids parameter.

Rx_igraph_transitivity_local_undirected_all,
graph,
isolates_num
Expand Down Expand Up @@ -2056,19 +2043,12 @@ ego_size <- function(
mode = c("all", "out", "in"),
mindist = 0
) {
ensure_igraph(graph)
mode <- igraph_match_arg(mode)
mode <- switch(mode, "out" = 1, "in" = 2, "all" = 3)
mindist <- as.numeric(mindist)

on.exit(.Call(Rx_igraph_finalizer))
.Call(
Rx_igraph_neighborhood_size,
graph,
as_igraph_vs(graph, nodes) - 1,
as.numeric(order),
as.numeric(mode),
mindist
neighborhood_size_impl(
graph = graph,
vids = nodes,
order = order,
mode = mode,
mindist = mindist
)
}

Expand Down Expand Up @@ -2170,27 +2150,13 @@ ego <- function(
mode = c("all", "out", "in"),
mindist = 0
) {
ensure_igraph(graph)
mode <- igraph_match_arg(mode)
mode <- switch(mode, "out" = 1, "in" = 2, "all" = 3)
mindist <- as.numeric(mindist)

on.exit(.Call(Rx_igraph_finalizer))
res <- .Call(
Rx_igraph_neighborhood,
graph,
as_igraph_vs(graph, nodes) - 1,
as.numeric(order),
as.numeric(mode),
mindist
neighborhood_impl(
graph = graph,
vids = nodes,
order = order,
mode = mode,
mindist = mindist
)
res <- lapply(res, function(x) x + 1)

if (igraph_opt("return.vs.es")) {
res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph))
}

res
}

#' @export
Expand All @@ -2205,21 +2171,13 @@ make_ego_graph <- function(
mode = c("all", "out", "in"),
mindist = 0
) {
ensure_igraph(graph)
mode <- igraph_match_arg(mode)
mode <- switch(mode, "out" = 1L, "in" = 2L, "all" = 3L)
mindist <- as.numeric(mindist)

on.exit(.Call(Rx_igraph_finalizer))
res <- .Call(
Rx_igraph_neighborhood_graphs,
graph,
as_igraph_vs(graph, nodes) - 1,
as.numeric(order),
as.integer(mode),
mindist
neighborhood_graphs_impl(
graph = graph,
vids = nodes,
order = order,
mode = mode,
mindist = mindist
)
res
}

#' @export
Expand Down Expand Up @@ -2449,15 +2407,13 @@ feedback_vertex_set <- function(graph, weights = NULL, algo = c("exact_ip")) {
#' girth(g)
#'
girth <- function(graph, circle = TRUE) {
ensure_igraph(graph)

on.exit(.Call(Rx_igraph_finalizer))
res <- .Call(Rx_igraph_girth, graph, as.logical(circle))
# girth_impl always computes circle; slightly less efficient when circle=FALSE
res <- girth_impl(graph = graph)
if (res$girth == 0) {
res$girth <- Inf
}
if (igraph_opt("return.vs.es") && circle) {
res$circle <- create_vs(graph, res$circle)
if (!circle) {
res$circle <- NULL
}
res
}
Expand Down Expand Up @@ -2768,7 +2724,7 @@ bfs <- function(
}

on.exit(.Call(Rx_igraph_finalizer))
res <- .Call(
res <- .Call( # bfs_simple_impl has different API (no callbacks)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is bfs_closure_impl(), similarly for DFS.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the comments in commit 86f4d82. Changed bfs_simple_impl to bfs_closure_impl and updated the reason: bfs_closure_impl returns only order, not rank/parent/pred/succ/dist. Similarly updated DFS to reference dfs_closure_impl returns only order/order_out, not parent/dist.

Rx_igraph_bfs,
graph,
root,
Expand Down Expand Up @@ -3024,7 +2980,7 @@ dfs <- function(
}

on.exit(.Call(Rx_igraph_finalizer))
res <- .Call(
res <- .Call( # dfs_closure_impl has different API (no callbacks)
Rx_igraph_dfs,
graph,
root,
Expand Down Expand Up @@ -3183,7 +3139,7 @@ count_components <- function(graph, mode = c("weak", "strong")) {
mode <- switch(mode, "weak" = 1L, "strong" = 2L)

on.exit(.Call(Rx_igraph_finalizer))
.Call(Rx_igraph_no_components, graph, mode)
.Call(Rx_igraph_no_components, graph, mode) # connected_components_impl returns membership, not count
}

#' Count reachable vertices
Expand Down