Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle issue #93 #94

Merged
merged 3 commits into from
Sep 11, 2015
Merged

handle issue #93 #94

merged 3 commits into from
Sep 11, 2015

Conversation

briatte
Copy link
Contributor

@briatte briatte commented Sep 10, 2015

The problem remains that I do not know how to avoid conflicts with igraph. If the user loads igraph after loading ggnet / ggnet2 / GGally, then it's easy to get this error:

> ggnet2(n, size = "degree")
 Error in is.bipartite(x) : Not a graph object 
5 stop("Not a graph object") 
4 is.bipartite(x) 
3 as.edgelist.sna(dat) 
2 sna::degree(net, gmode = is_dir, cmode = ifelse(x == "degree", 
    "freeman", x)) at ggnet2.R#484
1 ggnet2(n, size = "degree") 

@briatte briatte mentioned this pull request Sep 10, 2015
@briatte briatte changed the title expect warning when using 7+ node shapes expect warning when using 7+ node shapes, and handle issue #93 Sep 10, 2015
@briatte briatte changed the title expect warning when using 7+ node shapes, and handle issue #93 handle issue #93 Sep 10, 2015
schloerke added a commit that referenced this pull request Sep 11, 2015
@schloerke schloerke merged commit 0c2e736 into ggobi:dev Sep 11, 2015
@briatte
Copy link
Contributor Author

briatte commented Sep 18, 2015

Quick update: just in case we reintroduce igraph in the Suggests of GGally, as @elbamos suggests in #100, I have found a way to avoid any namespace conflict between it and sna.

The protection looks like this for ggnet (and is almost identical for ggnet2):

# prevent namespace conflict with igraph
if ("package:igraph" %in% search()) {
  y = ifelse(is_dir == "digraph", "directed", "undirected")
  z = c("indegree" = "in", "outdegree" = "out", "degree" = "all", "freeman" = "all")[ x ]
  data$weight = igraph::degree(igraph::graph.adjacency(as.matrix(net), mode = y), mode = z)
} else {
  data$weight = sna::degree(net, gmode = is_dir, cmode = ifelse(x == "degree", "freeman", x))
}

The code does not even need to know if igraph is loaded before network or sna—if igraph is loaded, it falls back to its own degree centrality function.

@elbamos
Copy link
Contributor

elbamos commented Sep 18, 2015

That's great! Can you share? I'll take a look and possibly integrate when I take a look at the whole thing.

On Sep 18, 2015, at 12:52 PM, François Briatte notifications@github.com wrote:

Quick update: just in case we reintroduce igraph in the Suggests of GGally, as @elbamos suggests in #100, I have found a way to avoid any namespace conflict between it and sna.


Reply to this email directly or view it on GitHub.

@briatte
Copy link
Contributor Author

briatte commented Sep 18, 2015

The code is in my comment above. If igraph is anywhere in the search() path, then the code converts the two objects that give the directedness and the centrality mode to their igraph equivalents, reconstructs an igraph object from the adjacency matrix of the network object, and computes centrality from that object.

This operation should never take too long except on very, very large graphs, and it should work fine on any binary one-mode adjacency matrix.

P.S. ggnetworkmap does not require the workaround since it does not call sna::degree.

@schloerke
Copy link
Member

Looks like a good solution to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants