Hi Gabor,

thank you for your quick reply. I do understand the problem that it will
may be hard or impossible to decide where some vertex or edge should be
incorporated into an existing graph. With that in mind, it is more clear
why some of my examples do not work. This situation may benefit from
improvements to documentation and error handling/messages. But who wants to
write that ;-).

Some other points though I would consider erroneous (ie adding an edge
object with compatible vertex id's but in fact adding an isolated vertex)
and I have a few other open issues, regarding iteration and indexing where
I think some improvements could be made. Partly I have started to write my
own convenience functions to overcome these quirks. Unfortunately I'm
currently quite busy and have little time to spare. I'll try to get
everything together in a systematic way and make a few suggestions how the
code may be improved (hopefully next week).

I don't know what would be the better place for the discussion. If you
prefer I can post future comments to the bug report.

Best,
Florian


On Tue, Jun 25, 2013 at 10:15 PM, Gábor Csárdi <[email protected]>wrote:

> OK, for the records, I created a bug report here:
> https://github.com/igraph/igraph/issues/502
>
> Gabor
>
>
> On Tue, Jun 25, 2013 at 10:26 AM, Gábor Csárdi <[email protected]>wrote:
>
>> Hi Florian,
>>
>> I agree this is confusing.
>>
>> The idea is that edges and vertices do not exist in isolation, but they
>> are always part of a graph. E() and V() return objects that reference the
>> graph they were created from. It is not expected that these objects will
>> work with other graphs, though. The problem is that igraph does not always
>> detect when you are trying to use them with other graphs.
>>
>> The get.edges(), neighbors(), etc. functions return plain R
>> vectors/lists, these do not reference the original graph.
>>
>> So the rule of thumb is that you should only use the result of E() and
>> G() with the graph you created them from.
>>
>> Btw. I think it would make sense to create a bug report from your email,
>> and then we can discuss things there if you are interested. You can create
>> a bug report here: https://github.com/igraph/igraph/issues/new Or I can
>> also create one, if you don't want to.
>>
>> Best,
>> Gabor
>>
>>
>> On Tue, Jun 25, 2013 at 5:29 AM, Florian Klinglmueller 
>> <[email protected]>wrote:
>>
>>> Hi,
>>>
>>> I have been playing around with igraph lately and think that it is a
>>> great package as it adds tremendous functionality to R. However, I
>>> continually get into trouble with basic edge and vertex operations,
>>> especially, adding and removing edges. I have added some examples of
>>> confusion at the end of this mail and attached the code.
>>>
>>> I think that there is a certain lack of consistency in how they operate,
>>> to the degree that I would consider it a bug. Maybe I'm just wrong in
>>> expecting that the examples given below should work in some consistent way.
>>> However, it makes it extremely difficult to decide whether a certain way
>>> to operate on some elements of a graph (e.g. get all edges via E(G) or
>>> get.edges(G,...)) will work for a certain problem or not (e.g. add them to
>>> a graph via + or add.edges, ...) when writing code. A major problem that I
>>> see is that it is essentially unclear how to write iterators over the nodes
>>> or edges of an igraph object (without resorting to exporting to other
>>> classes (eg via get.edgelist)).
>>>
>>> Best,
>>> Florian
>>>
>>>
>>> R 2.15.1> require(igraph)
>>> Loading required package: igraph
>>> R 2.15.1> # Consider the following graphs
>>> R 2.15.1>
>>> R 2.15.1> G4 <- graph.full(4)
>>> R 2.15.1> G <-  minimum.spanning.tree(G4)
>>> R 2.15.1> g <-  G4 - G
>>> R 2.15.1>
>>> R 2.15.1> G[]
>>> Loading required package: Matrix
>>> Loading required package: lattice
>>> 4 x 4 sparse Matrix of class "dgCMatrix"
>>>
>>> [1,] . 1 1 1
>>> [2,] 1 . . .
>>> [3,] 1 . . .
>>> [4,] 1 . . .
>>> R 2.15.1> g[]
>>> 4 x 4 sparse Matrix of class "dgCMatrix"
>>>
>>>
>>>> [1,] . . . .
>>>>
>>> [2,] . . 1 1
>>> [3,] . 1 . 1
>>> [4,] . 1 1 .
>>> R 2.15.1>
>>> R 2.15.1> # now here comes what confuses me
>>> R 2.15.1>
>>> R 2.15.1> for(e in E(G))
>>> +   print(delete.edges(G,e)[])
>>> 4 x 4 sparse Matrix of class "dgCMatrix"
>>>
>>> [1,] . . 1 1
>>> [2,] . . . .
>>> [3,] 1 . . .
>>> [4,] 1 . . .
>>> 4 x 4 sparse Matrix of class "dgCMatrix"
>>>
>>> [1,] . 1 . 1
>>> [2,] 1 . . .
>>> [3,] . . . .
>>> [4,] 1 . . .
>>> 4 x 4 sparse Matrix of class "dgCMatrix"
>>>
>>> [1,] . 1 1 .
>>> [2,] 1 . . .
>>> [3,] 1 . . .
>>> [4,] . . . .
>>> R 2.15.1>
>>> R 2.15.1> # works
>>> R 2.15.1>
>>> R 2.15.1> for(e in E(G))
>>> +   print(add.edges(g,e)[])
>>> Error in print(add.edges(g, e)[]) :
>>>   error in evaluating the argument 'x' in selecting a method for
>>> function 'print': Error in add.edges(g, e) :
>>>   At type_indexededgelist.c:269 : invalid (odd) length of edges vector,
>>> Invalid edge vector
>>> R 2.15.1>
>>> R 2.15.1> # gives an error
>>> R 2.15.1>
>>> R 2.15.1> # next
>>> R 2.15.1> e <- E(G)[1]
>>> R 2.15.1> E <- get.edge(G,1)
>>> R 2.15.1>
>>> R 2.15.1> delete.edges(G,e)[]
>>> 4 x 4 sparse Matrix of class "dgCMatrix"
>>>
>>> [1,] . . 1 1
>>> [2,] . . . .
>>> [3,] 1 . . .
>>> [4,] 1 . . .
>>> R 2.15.1> # removes one edge
>>> R 2.15.1>
>>> R 2.15.1> delete.edges(G,E)[]
>>> 4 x 4 sparse Matrix of class "dgCMatrix"
>>>
>>> [1,] . . . 1
>>> [2,] . . . .
>>> [3,] . . . .
>>> [4,] 1 . . .
>>> R 2.15.1> # removes two edges
>>> R 2.15.1>
>>> R 2.15.1> (G - e)[]
>>> 4 x 4 sparse Matrix of class "dgCMatrix"
>>>
>>> [1,] . . 1 1
>>> [2,] . . . .
>>> [3,] 1 . . .
>>> [4,] 1 . . .
>>> R 2.15.1> # works
>>> R 2.15.1>
>>> R 2.15.1> (G - E)[]
>>> 2 x 2 sparse Matrix of class "dgCMatrix"
>>>
>>> [1,] . .
>>> [2,] . .
>>> R 2.15.1> # empty graph with 2 nodes
>>> R 2.15.1>
>>> R 2.15.1> add.edges(g,e)
>>> Error in add.edges(g, e) :
>>>   At type_indexededgelist.c:269 : invalid (odd) length of edges vector,
>>> Invalid edge vector
>>> R 2.15.1> # error messag
>>> R 2.15.1>
>>> R 2.15.1> add.edges(g,E)[]
>>> 4 x 4 sparse Matrix of class "dgCMatrix"
>>>
>>> [1,] . 1 . .
>>> [2,] 1 . 1 1
>>> [3,] . 1 . 1
>>> [4,] . 1 1 .
>>> R 2.15.1> # works
>>> R 2.15.1>
>>> R 2.15.1> g + E
>>> Error in `+.igraph`(g, E) : Cannot add unknown type to igraph graph
>>> R 2.15.1> # error
>>> R 2.15.1>
>>> R 2.15.1> (g + e)[]
>>> 5 x 5 sparse Matrix of class "dgCMatrix"
>>>
>>> [1,] . . . . .
>>> [2,] . . 1 1 .
>>> [3,] . 1 . 1 .
>>> [4,] . 1 1 . .
>>> [5,] . . . . .
>>> R 2.15.1> # adds a node ???
>>> R 2.15.1>
>>>
>>> _______________________________________________
>>> igraph-help mailing list
>>> [email protected]
>>> https://lists.nongnu.org/mailman/listinfo/igraph-help
>>>
>>>
>>
>
> _______________________________________________
> igraph-help mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/igraph-help
>
>


-- 
-------------------------
Center for Medical Statistics, Informatics and Intelligent Systems
Section of Medical Statistics
Medical University of Vienna
--
Spitalgasse 23
1090 Wien
Austria
--
Ph.: +43 1 40400 7483 (7477 Fax)
[email protected]
_______________________________________________
igraph-help mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/igraph-help

Reply via email to