Created
March 26, 2015 11:33
-
-
Save smbache/282bf12bfcfc6ceaee1d to your computer and use it in GitHub Desktop.
Attempt to answer tweet: https://twitter.com/osazuwa/status/580894347094294529
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't think this will work in general, e.g. for things like
I also really don't know what's wrong with writing
V(g)$color
.