Skip to content

delete_edges bug and counterintuitive add_edges behaviour (and workaround) #550

@jessexknight

Description

@jessexknight

Describe the bug
The documented behaviour of delete_edges is not correct, and add_edges does some counterintuitive things.

To reproduce

library('igraph')
set.seed(1)
G = make_ring(10)
E(G)$color='blue'
e = get.edgelist(G) # 10x2 matrix
i = sample(ecount(G),3) # random edges
print(e[i,]) # random edges' vertices
layout = layout_nicely(G) # save layout
plot(G,layout=layout); print(ecount(G))
G = delete_edges(G,apply(e[i,],1,paste0,collapse='|')) # OK
# G = delete_edges(G,c(t(e[i,]))) # incorrect (1)
plot(G,layout=layout); print(ecount(G))
# G = add_edges(G,apply(e[i,],1,paste0,collapse='|'),color='red') # error (2)
G = add_edges(G,c(t(e[i,])),color='red') # OK
plot(G,layout=layout); print(ecount(G))

correctly yields:

     [,1] [,2]
[1,]    9   10
[2,]    4    5
[3,]    7    8
[1] 10
[1] 7
[1] 10

However, the commented uses of delete_edges (1) and add_edges (2) do not work:

  1. delete_edges with the numeric argument removes twice as many edges as described in docs, yielding "10, 4, 7" for the last three outputs instead of "10, 7, 10".
  2. add_edges with the character argument throws an error Invalid vertex name(s). While this input format is not documented, I was expecting symmetry with delete_edges.
  3. Semi-related: it's a bit counterintuitive that passing the matrix get.edgelist directly to add_edges results in the wrong edges, since R iterates over matrix data by row then column. So, the matrix must be transposed (the c() above is actually not needed).

Version information
igraph v1.3.2 on linux mint 20.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions