rigraph icon indicating copy to clipboard operation
rigraph copied to clipboard

Standardize API parameter naming: `nodes` → `n`, `vids` → `vertices`

Open Copilot opened this issue 4 months ago • 0 comments

Addresses inconsistent parameter naming across the API where "nodes", "vids", and "vertices" were used interchangeably for similar concepts, reducing predictability.

Changes

Implements the naming convention agreed in issue discussion:

  • n for scalar vertex count (graph generators)
  • vertices for vertex sequences (centrality, structural, path functions)

Graph generators (nodesn)

  • sample_traits_callaway(), sample_traits(), sample_grg()
  • sample_pref(), sample_asym_pref(), sample_forestfire()

Centrality functions (vidsvertices)

  • page_rank(), closeness(), strength(), harmonic_centrality(), diversity()

Centrality functions (nodesvertices)

  • alpha_centrality(), power_centrality()

Structural properties (nodesvertices)

  • constraint(), ego(), ego_size(), make_ego_graph()

Path functions (vidsvertices)

  • eccentricity()

Example

# Before (inconsistent)
sample_traits_callaway(nodes = 100, types = 3)
alpha_centrality(g, nodes = V(g))
page_rank(g, vids = V(g))

# After (consistent)
sample_traits_callaway(n = 100, types = 3)
alpha_centrality(g, vertices = V(g))
page_rank(g, vertices = V(g))

Deprecated wrappers updated to maintain backward compatibility.

Original prompt

This section details on the original issue you should resolve

<issue_title>Inconsistent naming: "vertex" vs "node"</issue_title> <issue_description>In the interest of predictability, we should ensure that the API uses "vertex" consistently and avoids "node".

Currently, "node" us used:

  • Sometimes in place of vids, see igraph/rigraph#691
  • To specify the number of vertices in some graph generators, see e.g. sample_traits_callaway() and other similar functions. Grep for @param nodes.

This issue refers specifically to the API, which should be predictable. Using both "node" and "vertex" in the documentation text is less of an issue.</issue_description>

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

@schochastics I tried to gather all functions that use `c("nodes", "vids", "v","vertex", "vertices","n")` My suggestion to consolidate:
  • use n for number of nodes (scalar)
  • use vertices for subset of nodes (vector of vertex ids/names, could be a single vertex though)
  • use v (or vertex) for a specific vertex (scalar, can neverf be a vector)

This would eliminate vids and nodes

@szhorvat What do you think?

library(igraph)
#> 
#> Attaching package: 'igraph'
#> The following objects are masked from 'package:stats':
#> 
#>     decompose, spectrum
#> The following object is masked from 'package:base':
#> 
#>     union
fns <- ls("package:igraph")

has_arg <- function(fname, arg) {
  obj <- get(fname, envir = asNamespace("igraph"))
  is.function(obj) && arg %in% names(formals(obj))
}

args <- c("nodes", "vids", "v","vertex", "vertices","n","vid")
purrr:::map_dfr(
  args,
  function(arg) {
    data.frame(
      fn = fns[sapply(fns, has_arg, arg = arg)],
      arg = arg
    )
  }
)
#>                                  fn      arg
#> 1                  alpha_centrality    nodes
#> 2                  alpha.centrality    nodes
#> 3        asymmetric.preference.game    nodes
#> 4                            bonpow    nodes
#> 5              callaway.traits.game    nodes
#> 6                   centr_betw_tmax    nodes
#> 7                    centr_clo_tmax    nodes
#> 8                 centr_degree_tmax    nodes
#> 9                  centr_eigen_tmax    nodes
#> 10  centralization.betweenness.tmax    nodes
#> 11    centralization.closeness.tmax    nodes
#> 12       centralization.degree.tmax    nodes
#> 13       centralization.evcent.tmax    nodes
#> 14                       constraint    nodes
#> 15                              ego    nodes
#> 16                         ego_size    nodes
#> 17               establishment.game    nodes
#> 18                 forest.fire.game    nodes
#> 19               graph_from_graphdb    nodes
#> 20                    graph.graphdb    nodes
#> 21               graph.neighborhood    nodes
#> 22                         grg.game    nodes
#> 23                   make_ego_graph    nodes
#> 24          make_neighborhood_graph    nodes
#> 25                     neighborhood    nodes
#> 26                neighborhood_size    nodes
#> 27                neighborhood.size    nodes
#> 28                 power_centrality    nodes
#> 29                  preference.game    nodes
#> 30                 sample_asym_pref    nodes
#> 31                sample_forestfire    nodes
#> 32                       sample_grg    nodes
#> 33                      sample_pref    nodes
#> 34                    sample_traits    nodes
#> 35           sample_traits_callaway    nodes
#> 36               adjacent.triangles     vids
#> 37             betweenness.estimate     vids
#> 38                        closeness     vids
#> 39               closeness.estimate     vids
#> 40                  count_triangles     vids
#> 41                        diversity     vids
#> 42                     eccentricity     vids
#> 43             estimate_betweenness     vids
#> 44               estimate_closeness     vids
#> 45                  graph.diversity     vids
#> 46          graph.isoclass.subgraph     vids
#> 47                        graph.knn     vids
#> 48                   graph.strength     vids
#> 49              harmonic_centrality     vids
#> 50                 induced_subgraph     vids
#> 51                 induced.subgraph     vids
#> 52                              knn     vids
#> 53                 local_efficiency     vids
#> 54                        page_rank     vids
#> 55                        page.rank     vids
#> 56                       similarity     vids
#> 57                  similarity.dice     vids
#> 58        similarity.invlogweighted     vids
#> 59               similarity.jaccard     vids
#> 60                         strength     vids
#> 61                         subgraph     vids
#> 62                     transitivity     vids
#> 63                adjacent_vertices        v
#> 64                      betweenness        v
#> 65                      bibcoupling        v
#> 66                 ...

</details>

- Fixes igraph/rigraph#692

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

Copilot avatar Oct 27 '25 23:10 Copilot