rigraph icon indicating copy to clipboard operation
rigraph copied to clipboard

feat: standardize optional vertex parameters to use `NULL` default

Open Copilot opened this issue 2 months ago • 1 comments

  • [x] Merge main branch
  • [x] Resolve merge conflicts
  • [x] Remove spurious system headers from .dd files (cpp11.dd, rinterface.dd)
  • [x] Move optional VERTEX subtraction logic outside of .Call() as requested by @maelle
  • [x] Test changes - all tree tests pass (79 tests)
Original prompt

This section details on the original issue you should resolve

<issue_title>Standardize the handling of optional vertex parameters</issue_title> <issue_description>The handling, and default value, of optional vertex parameters should be standardized, and Stimulus should be updated accordingly.

There are currently two C functions which take an optional vertex parameter: igraph_random_spanning_tree() and igraph_fundamental_cycles(). Only the former is exposed at the moment. We need a decision on this issue before I expose the latter.

In C, these two functions interpret a negative vertex index as not passing a vertex.

In R, the situation is more complicated because vertices can be referred to either by a string name or by an integer index. Both must be supported.

IMO there are two reasonable options:

  1. Signal that no vertex is provided by passing a non-positive value. The default parameter value should be 0. NULL is not allowed, nor are passing multiple vertices.
  2. Signal that no vertex is provided by passing NULL. The default parameter value should be NULL. Non-positive integers are not allowed. Multiple vertices are not allowed.

We currently have (1) mostly implemented. The auto-generated code looks like this:

  if (!is.null(vid)) vid <- as_igraph_vs(graph, vid)
  if (length(vid) == 0) {
    stop("No vertex was specified")
  }

However, currently, OPTIONAL VERTEX, without an explicit default, uses NULL as the default, which triggers the "No vertex was specified" error. If we go with choice (1), Stimulus should be updated to use 0 instead of NULL as the default. If we go with choice (2), the autogen code template must be updated for this.

@krlmlr, can you make a decision on this? When that is done, can you adapt Stimulus, @Antonov548 ?</issue_description>

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

@maelle On the R side, having `NULL` as default makes sense **for the interface**. Now, we can internally convert it to whatever the C side needs.

https://design.tidyverse.org/defaults-short-and-sweet.html</comment_new> <comment_new>@krlmlr

I agree that the default on the interface should be NULL .

@Antonov548: Can you please help with Stimulus? Are the requirements clear?</comment_new> <comment_new>@Antonov548

igraph_fundamental_cycles

Sorry, I'm not follow anymore. From the all pull requests and discussion I have thoughts that changes to Stimulus are not required. Is there still anything I need to update in Stimulus?

Can you poine me please what should be updated?</comment_new> <comment_new>@szhorvat

Since we're going with option 2, I think you're right. But to be sure, it'd be great to actually implement this (by removing the default of 0 from igraph_random_spanning_tree and letting it use the OPTIONAL default of NULL) and make sure it all works.</comment_new>
  • Fixes igraph/rigraph#1572

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Oct 26 '25 20:10 Copilot

@copilot: Merge main, resolve conflicts, adhere to feedback.

krlmlr avatar Nov 04 '25 21:11 krlmlr