Skip to content

Standardize the handling of optional vertex parameters #1572

@szhorvat

Description

@szhorvat

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 ?

Metadata

Metadata

Assignees

Labels

AI 🤖For issues that can be handled by a coding agent. A scheduled workflow will look at those.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions