$ operator
I wrote a one-liner to add $ support for igraph. Is this reasonable?
`$.igraph` <- function(x, i, ...) induced_subgraph(x, ego(x, 1, i)[[i]])
If so I have a PR ready: https://github.com/igraph/rigraph/pull/167
Is this reasonable? $ is used to access graph attributes.
Yes, I am afraid that we already use $ for something else. If you want an operator for ego you need to choose another one, or create your own via %ego%.
Oh, that works. Maybe something like %neighbors% instead?
--t
On Tue, Sep 6, 2016 at 1:13 AM, Gábor Csárdi [email protected] wrote:
Yes, I am afraid that we already use $ for something else. If you want an operator for ego you need to choose another one, or create your own via %ego%.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/igraph/rigraph/issues/168#issuecomment-244880377, or mute the thread https://github.com/notifications/unsubscribe-auth/AAARIq5BwdNVe-xd_zWP36DdF9QIfH2Gks5qnSCWgaJpZM4J1Xfn .
Alright I updated my pull request to call it %around%, i.e. around.igraph(g, v) == g %around% v.
%ego% didn't seem like the best choice because the ego(g, 1, v) function doesn't return a graph.
How is it different from make_ego_graph?
Moreover, and this is just an opinion of a long-time user:
I do not like such use of binary operators in R too much. That is, creating an operator, say %operator%, such that it only makes sense to call x %operator% y, but not y %operator% x for specific x and y. Why not just write a function operator()? If you really want just the "sequential" syntax, you could call it with magrittr pipe, provided that operator() accepts igraph object as the first argument, i.e.:
graph %>% operator(i)
Thats about the same amount of characters that you need to type-in.
of course most of the time that's how an operator is implemented anyhow (elsewhere in igraph too)
around.igraph <- function(x, i) induced_subgraph(x, ego(x, 1, i)[[i]])
"%around%" <- function(x, y) around.igraph(x, y)
I've only been using R since around 2005, not from the beginning, but this is a pretty pervasive pattern. x %>% around(y) is pretty similar to x %around% y, the latter is just syntactic sugar. And you're right, it's a similar number of chars.