Skip to content

feat: Add graph_join() function to R interface#2411

Draft
Copilot wants to merge 16 commits intomainfrom
copilot/add-igraph-join-function
Draft

feat: Add graph_join() function to R interface#2411
Copilot wants to merge 16 commits intomainfrom
copilot/add-igraph-join-function

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 26, 2025

Summary: Add igraph_join() to R

Successfully added the graph_join() function to the R interface for igraph, exposing the igraph_join() C function that was added in version 0.10.11.

Implementation Completed

  • Create a high-level graph_join() R function similar to disjoint_union() in R/operators.R
  • Add an operator form %j% for convenience (similar to %du% for disjoint_union)
  • Handle graph attributes appropriately (note: C implementation does not preserve attributes yet)
  • Add comprehensive tests in tests/testthat/test-operators.R
  • Add documentation with examples
  • Export the new function and operator in NAMESPACE
  • Run full test suite to verify implementation (7335 tests pass)
  • Fix documentation issues
  • Run security checks (no issues)
  • Update documentation to use proper math notation per updated AGENTS.md instructions
  • Merge main branch and ensure compatibility with latest changes
  • Use named arguments for _impl function calls per project convention
  • Run devtools::check() - passes with 0 errors, 0 warnings, 0 notes
  • Rename to graph_join() to avoid name conflicts with other packages
  • Add experimental badge and concept tag per AGENTS.md requirements

What is graph_join()?

The graph_join() function creates the join of two disjoint graphs by:

  1. Relabeling vertices of the second graph with new vertex IDs
  2. Forming the disjoint union of the two graphs
  3. Adding edges between ALL vertices from the first graph to ALL vertices in the second graph

For graphs with \eqn{|V_1|}, \eqn{|V_2|} vertices and \eqn{|E_1|}, \eqn{|E_2|} edges:

  • Result has \eqn{|V_1|+|V_2|} vertices
  • Result has \eqn{|E_1|+|E_2|+|V_1| \times |V_2|} edges (undirected) or \eqn{|E_1|+|E_2|+2 \times |V_1| \times |V_2|} edges (directed)

Usage Examples

# Basic usage
g1 <- make_star(10, mode = "undirected")
g2 <- make_ring(5)
gj <- graph_join(g1, g2)

# Or using the operator
gj <- g1 %j% g2

Naming

The function is named graph_join() (rather than just join()) to avoid conflicts with the 19 other CRAN packages that export a function named join(), and to make it clear this is a graph-specific operation.

Testing

All tests pass:

  • ✓ Basic undirected graph join
  • ✓ Operator form %j%
  • ✓ Directed graph support
  • ✓ Error handling for mixed directedness
  • ✓ Vertex ordering preservation
  • ✓ 7335 total package tests pass
  • ✓ devtools::check() passes with 0 errors, 0 warnings, 0 notes

AGENTS.md Compliance

  • ✓ Examples included

  • ✓ Tests included

  • ✓ Proper documentation with arguments and return values

  • ✓ Concept tag for pkgdown reference index

  • ✓ Experimental badge via lifecycle

  • ✓ Named arguments in _impl calls

  • ✓ Math notation using \eqn{}

  • ✓ Final check with devtools::check()

  • Fixes Add igraph_join() to R #1345

Original prompt

This section details on the original issue you should resolve

<issue_title>Add igraph_join() to R</issue_title>
<issue_description>igraph_join() was added in 0.10.11, see: https://igraph.org/c/html/latest/igraph-Operators.html#igraph_join

The interface should be similar to disjoint_union(), but note that igraph_join() does not have a variant that takes an arbitrary number of graphs (not really practically needed). You might consider adding an operator form as well.</issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits October 26, 2025 11:58
- Add join() function and %j% operator in R/operators.R
- Add comprehensive tests for join() in test-operators.R
- Update documentation with examples
- Export join and %j% in NAMESPACE

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_join function to R feat: Add join() function to R interface Oct 26, 2025
Copilot AI requested a review from krlmlr October 26, 2025 12:05
Comment thread .gitignore Outdated
@krlmlr
Copy link
Copy Markdown
Contributor

krlmlr commented Oct 26, 2025

@copilot: The merge updated instructions, adapt.

Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 26, 2025

@copilot: The merge updated instructions, adapt.

Updated the documentation to use proper math notation (\eqn{...}) for formulas as specified in the updated AGENTS.md instructions. Changed notation like |V1| to \eqn{|V_1|} and |E1|+|E2|+|V1|*|V2| to \eqn{|E_1|+|E_2|+|V_1| \times |V_2|}. Commit d169973.

Copilot AI requested a review from krlmlr October 26, 2025 17:36
Copy link
Copy Markdown
Contributor

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

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

Looks good, unsure about authorship, haven't checked.

@krlmlr krlmlr removed their assignment Oct 26, 2025
@krlmlr krlmlr requested a review from schochastics October 26, 2025 20:54
@krlmlr
Copy link
Copy Markdown
Contributor

krlmlr commented Oct 27, 2025

@copilot: Merge main, run final checks, fix.

Copilot AI and others added 2 commits October 27, 2025 23:08
Align with project convention to use named arguments for all _impl function calls.

Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 27, 2025

@copilot: Merge main, run final checks, fix.

Merged main branch successfully (commit 5efd23c). Updated join() to use named arguments when calling join_impl(left = g1, right = g2) per project convention (commit e49da0a). All tests pass: 7331 total (3 expected warnings, 2 skips).

Copilot AI requested a review from krlmlr October 27, 2025 23:13
Copy link
Copy Markdown
Contributor

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

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

@copilot: Did you run devtools::check() ?

Fix R CMD check WARNING by documenting the x and y parameters used by the %j% operator.

Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 28, 2025

@copilot: Did you run devtools::check() ?

Yes, ran devtools::check() and found a WARNING about undocumented parameters. Fixed by adding @param x,y Graph objects. to document the operator's parameters (commit d8582cb). Check now passes with 0 errors, 0 warnings, 0 notes.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cran.rstudio.com
    • Triggering command: /opt/R/4.5.1/lib/R/bin/exec/R --no-restore --no-echo --args nextArgigraph_2.2.1.9001.tar.gznextArg--as-crannextArg--timingsnextArg--no-manual (dns block)
  • packagemanager.posit.co
    • Triggering command: /opt/R/4.5.1/lib/R/bin/exec/R --no-restore --no-echo --args nextArgigraph_2.2.1.9001.tar.gznextArg--as-crannextArg--timingsnextArg--no-manual (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from krlmlr October 28, 2025 00:12
Comment thread R/operators.R
#' ## A star and a ring
#' g1 <- make_star(10, mode = "undirected")
#' g2 <- make_ring(5)
#' print_all(g1 %j% g2)
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.

do we need print_all?

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.

What does it do?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copilot should be taught to prefer plotting instead of printing graphs. I wanted to comment on some of these issues today but my wrist is not doing well, can't type. I fell on the ice and hurt it a few days ago. I'll get back to you later. Dictation doesn't work that well yet on macOS.

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.

Sorry to hear that, hope your wrist is better.

We could review the pkgdown rendering of all examples and decide on a course of actions. I'm not sure I'm on board with plotting by default just yet.

@szhorvat
Copy link
Copy Markdown
Member

I'd call this graph_join(), not join(). The concept is too graph theory specific.

@krlmlr
Copy link
Copy Markdown
Contributor

krlmlr commented Oct 28, 2025

Why is this operation not called cross() ? Just curious.

No strong opinion re naming.

@szhorvat
Copy link
Copy Markdown
Member

The usual name for this operation is join. I don't know why it's called join, but the term "cross" evokes a product for me, so I would not have called it that.

@krlmlr
Copy link
Copy Markdown
Contributor

krlmlr commented Nov 1, 2025

@krlmlr
Copy link
Copy Markdown
Contributor

krlmlr commented Nov 1, 2025

@copilot: Merge main and rename to graph_join() .

Copilot AI and others added 2 commits November 1, 2025 11:00
Rename the function from join() to graph_join() to avoid name conflicts with other packages and make the purpose clearer. The %j% operator is retained for convenience.

Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 1, 2025

@copilot: Merge main and rename to graph_join() .

Merged main branch and renamed function from join() to graph_join() (commit ce0cce7). The %j% operator is retained for convenience. All tests pass (7335 total), and devtools::check() passes with 0 errors, 0 warnings, 0 notes.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cran.rstudio.com
    • Triggering command: /opt/R/4.5.2/lib/R/bin/exec/R --no-restore --no-echo --args nextArgigraph_2.2.1.9003.tar.gznextArg--as-crannextArg--timingsnextArg--no-manual (dns block)
  • packagemanager.posit.co
    • Triggering command: /opt/R/4.5.2/lib/R/bin/exec/R --no-restore --no-echo --args nextArgigraph_2.2.1.9003.tar.gznextArg--as-crannextArg--timingsnextArg--no-manual (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title feat: Add join() function to R interface feat: Add graph_join() function to R interface Nov 1, 2025
@krlmlr
Copy link
Copy Markdown
Contributor

krlmlr commented Nov 1, 2025

@copilot: Merge main, carefully follow all AGENTS.md instructions.

Copilot AI and others added 2 commits November 1, 2025 16:36
Add lifecycle experimental badge and @concept tag per AGENTS.md requirements for new functions.

Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 1, 2025

@copilot: Merge main, carefully follow all AGENTS.md instructions.

Merged main branch (6 new commits) and added missing AGENTS.md requirements (commit 643da28):

  • Added experimental badge via r lifecycle::badge("experimental")
  • Added @concept graph_operators tag for pkgdown reference indexing
  • Verified all other requirements already met: examples, tests, documentation, named arguments, math notation

All tests pass (7335 total), devtools::check() passes with 0 errors, 0 warnings, 0 notes.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cran.rstudio.com
    • Triggering command: /opt/R/4.5.2/lib/R/bin/exec/R --no-restore --no-echo --args nextArgigraph_2.2.1.9003.tar.gznextArg--as-crannextArg--timingsnextArg--no-manual (dns block)
  • packagemanager.posit.co
    • Triggering command: /opt/R/4.5.2/lib/R/bin/exec/R --no-restore --no-echo --args nextArgigraph_2.2.1.9003.tar.gznextArg--as-crannextArg--timingsnextArg--no-manual (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copy link
Copy Markdown
Contributor

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

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

@copilot: Merge main, follow feedback and updated agent instructions.

Comment thread R/operators.R Outdated
#'
#' Both graphs need to have the same directedness, i.e. either both directed or
#' both undirected. If both graphs are directed, then for each pair of vertices
#' v, u in graphs G1, G2 we add edges (v, u) and (u, v) to maintain completeness.
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.

Render as equations.

Comment thread R/operators.R Outdated
ensure_igraph(g1)
ensure_igraph(g2)

on.exit(.Call(R_igraph_finalizer))
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.

Remove.

Copilot AI and others added 2 commits November 1, 2025 17:22
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
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_join() to R

4 participants