-
-
Notifications
You must be signed in to change notification settings - Fork 206
delete_edges bug and counterintuitive add_edges behaviour (and workaround) #550
Copy link
Copy link
Closed
Labels
Description
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:
delete_edgeswith 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".add_edgeswith the character argument throws an errorInvalid vertex name(s). While this input format is not documented, I was expecting symmetry withdelete_edges.- Semi-related: it's a bit counterintuitive that passing the matrix
get.edgelistdirectly toadd_edgesresults in the wrong edges, since R iterates overmatrixdata by row then column. So, the matrix must be transposed (thec()above is actually not needed).
Version information
igraph v1.3.2 on linux mint 20.1
Reactions are currently unavailable