Reputation: 894
I have two graph objects made from scratch with Networkx (Python 3.8). To help understanding the situation this is a summary snippet:
G = nx.Graph()
Z = nx.Graph()
#some work here to get data for nodes and edges
G.add_nodes_from([(data["id"], {"origin": data["origin"], "text": data["text"]})])
#some other work in order to hash data for improved nodes privacy
G.add_edge(h.hexdigest(), data["x"])
Z.add_edge(h.hexdigest(), data["x"], weight=polarity) #here polarity is a simple double value
Now, the problem is that I want to export those objects in order to do some work with RStudio and the package igraph. Until now I've tried the following things (without any luck):
Read_Adjacency()
and then re-export with the function Write_Adjacency()
(hoping that with this intermediate step it somehow make the format understandable by igraph)How can I do ?
This is the code I use in RStudio:
ADJACENCY=read.csv("myadjlist.csv",header=FALSE,row.names=NULL,sep=";")
ADJACENCY=as.matrix(ADJACENCY)
#then we create the graph
G=graph_from_adjacency_matrix(ADJACENCY, mode="undirected")
And the error:
Error in graph.adjacency.dense(adjmatrix, mode = mode, weighted = weighted, : At structure_generators.c:274 : Non-square matrix, Non-square matrix
This is my adjacency list:
Upvotes: 3
Views: 2037
Reputation: 728
igraph
nowadays support direct conversion from and to networkx
objects. See https://igraph.org/python/doc/api/igraph.Graph.html#from_networkx for more details. If you first convert to an igraph
object (in Python), write it to a file, and then read it back in using igraph
(in R), this should work correctly.
Upvotes: 2