Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 26, 2025

Exposes the existing C function igraph_count_loops() to the R interface as count_loops().

Changes

  • R/structural-properties.R: Added count_loops() function that returns the total number of self-loop edges as a numeric scalar
  • Documentation: Integrated into existing which_multiple help page alongside any_loop() and which_loop()
  • Tests: Added test coverage for graphs with loops, without loops, and edge cases

Usage

library(igraph)

# Graph with 3 self-loops
g <- make_graph(c(1, 1, 2, 2, 3, 3, 4, 5))
count_loops(g)  # Returns 3

# Complements existing loop detection functions
any_loop(g)     # Returns TRUE
which_loop(g)   # Returns c(TRUE, TRUE, TRUE, FALSE)

The function follows the established pattern of count_multiple() and integrates with the existing family of loop/multiple edge detection functions.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add igraph_count_loops() to R</issue_title>
<issue_description>Add igraph_count_loops() to R. I suggest count_loops() as the name. I would consider this low priority.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits October 26, 2025 13:00
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Copilot AI changed the title [WIP] Add igraph_count_loops() function to R feat: Add count_loops() to R interface Oct 26, 2025
Copilot AI requested a review from krlmlr October 26, 2025 13:05
Copilot finished work on behalf of krlmlr October 26, 2025 13:05
@krlmlr krlmlr requested a review from schochastics October 26, 2025 17:36
@krlmlr krlmlr removed their assignment Oct 26, 2025
Copy link
Contributor

@schochastics schochastics left a comment

Choose a reason for hiding this comment

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

LGTM

@krlmlr krlmlr marked this pull request as ready for review October 28, 2025 21:05
@krlmlr krlmlr enabled auto-merge (squash) October 28, 2025 21:05
@krlmlr krlmlr merged commit 4bfea65 into main Oct 28, 2025
5 checks passed
@krlmlr krlmlr deleted the copilot/add-igraph-count-loops branch October 28, 2025 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add igraph_count_loops() to R

3 participants