Closed gaborcsardi closed 10 years ago
It is relatively hard to do this with the R operators that we are allowed to redefine, in a way that is readable. The most logical would be probably to define &
for graphs, and also add additional functionality to the V()
and E()
functions. Then we could write things like
karate & V(1:10) # Induced subgraph including vertices 1-10
karate & V(color=="red") # Induced subgraph including the red vertices
karate & V(degree > 0) # Induced subgraph of the non-isolate vertices
and similarly for edges, here all vertices are kept:
karate & E(1:10) # Keep only edges 1-10
karate & E(inc(1:5,10)) # Keep edges incident to vertices 1-5 and 10
karate & E(weight >= 1) # Keep edges with large enough weight
They can be combined like this:
karate & E(weight >= 1) & V(degree > 0)
This will remove edges with small weight, and then remove the isolate vertices.
for reference, i understand that people are quite fond of the syntax used in dplyr: https://github.com/hadley/dplyr specifically:
obviously, we'd want something modified more for graphs rather than data frames. i'm not sure how easy it is to use such a syntax, but seemed like potentially worth mentioning....
On Thu, May 8, 2014 at 9:57 PM, Gabor Csardi notifications@github.comwrote:
It is relatively hard to do this with the R operators that we are allowed to redefine, in a way that is readable. The most logical would be probably to define & for graphs, and also add additional functionality to the V() and E() functions. Then we could write things like
karate & V(1:10) # Induced subgraph including vertices 1-10 karate & V(color=="red") # Induced subgraph including the red vertices karate & V(degree > 0) # Induced subgraph of the non-isolate vertices
and similarly for edges, here all vertices are kept:
karate & E(1:10) # Keep only edges 1-10 karate & E(inc(1:5,10)) # Keep edges incident to vertices 1-5 and 10 karate & E(weight >= 1) # Keep edges with large enough weight
They can be combined like this:
karate & E(weight >= 1) & V(degree > 0)
This will remove edges with small weight, and then remove the isolate vertices.
— Reply to this email directly or view it on GitHubhttps://github.com/igraph/xdata-igraph/issues/39#issuecomment-42629175 .
perhaps consider allowing the quest for eudaimonia to guide you openconnecto.me, jovo.me
dplyr
is great, and you are free to use its chaining operator for igraph:
library(igraph)
library(dplyr)
G <- graph.ring(10)
G %.% induced.subgraph(vids=1:5) %.% degree()
# [1] 1 2 2 2 1
If this is what you mean by the syntax used in dplyr.
If you want to have new igraph functions, please open separate issues for them.
The syntax as is seems pretty good to me now that I know how works
i'm happy if daniel is happy :) (i'm happy anyway, actually :-)
On Fri, May 9, 2014 at 8:47 AM, Daniel Sussman notifications@github.comwrote:
The syntax as is seems pretty good to me now that I know how works
— Reply to this email directly or view it on GitHubhttps://github.com/igraph/xdata-igraph/issues/39#issuecomment-42667256 .
perhaps consider allowing the quest for eudaimonia to guide you openconnecto.me, jovo.me
When a function is called on a subgraph of a graph, one would not need to explicitly create the subgraph, just use the more compact notation. From #38.