Open szhorvat opened 1 year ago
This relates to the more general problem that the auto-generated R-to-C glue code does not properly validate scalars. If a scalar is expected, but the vector that is passed has length different from 1, then the code blindly take the first element.
When there are multiple elements, this just takes the first one, which is not a great sin, but it can still lead to confusion, as you see here. However, if there are zero elements, then we have an out-of-bounds access. This should be fixed in the interface generator.
In functions that take a single vertex ID as a parameter (instead of a vertex sequence), negative IDs, which should be invalid, are often handled in a strange way. Take for example
shortest_paths()
:This is fine:
This is fine:
What is happening here?
It turns out that internally,
shortest_paths
usesas.igraph.vs()
on thefrom
parameter, and effectively indexes into the vertex ID vector. And with R's usual quirkiness,-1
means "everything except-1
":Then all but the first element gets ignored. Thus, unintuitively,
-1
ends up meaning2
.