Skip to content

Instantly share code, notes, and snippets.

@smbache
Created March 26, 2015 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smbache/282bf12bfcfc6ceaee1d to your computer and use it in GitHub Desktop.
Save smbache/282bf12bfcfc6ceaee1d to your computer and use it in GitHub Desktop.
# Allow for V(g) %$% color or g %>% V %$% color
#
# Since %$% uses the generic `with` method, it is possible to tweek this to
# deal with special cases like this. I know little about igraph, but this
# may work.
#
with.igraph.vs <- function(data, expr, ...) {
eval(substitute(data$c, list(c = substitute(expr))))
}
# Example
library(magrittr)
library(igraph)
g <- erdos.renyi.game(100, 2/100)
V(g)$color <- "green"
g %>% V %$% color
@gaborcsardi
Copy link

I don't think this will work in general, e.g. for things like

V(g)[subset] $ color <- "red"

I also really don't know what's wrong with writing V(g)$color.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment