Search code examples
crigraphadjacency-matrix

igraph R and C, writing and reading adjacency matrix with attributes


I would like to use igraph R to visualize a network graph which I create with igraph C.

So far I have saved the graph in C with these commands:

FILE *ofile;
ofile=fopen("AdjacencyMatrix.csv", "w"); 
igraph_write_graph_pajek(&g, ofile);
fclose(ofile);

And then read the file from R with this one:

g<- read.graph("AdjacencyMatrix.csv", format = c("pajek"))

which works fine.

Now I would like to add attributes to the edges in order to distinguish between two groups of edges. In order to do so I am using the example from the igraph C Tutorial 'Example 12.2. File examples/simple/cattributes2.c' and just add the above mentioned lines at the end to save the graph in a csv file. Now two problems arise:

a) If I use the pajek command to save the file, the saved file does not contain any of the attributes but just the connections

b) If I use 'igraph_write_graph_graphml(&g, ofile, /prefixattr=/ 1);' instead, I am getting the following error message when trying to read the file in igraph R:

g<- read.graph("AdjacencyMatrix.csv", format = c("graphml"))

Warning message: In .Call("R_igraph_read_graph_graphml", file, as.numeric(index), : At foreign-graphml.c:443 :Could not add vertex ids, there is already an 'id' vertex attribute

Does anyone have a suggestion how I can solve either of the problems?


Solution

  • Re a): the Pajek format does not support arbitrary attributes, only a few dedicated ones; see the documentation of igraph_read_graph_pajek for more details.

    Re b): The message that you get is not an error message but only a warning. Feel free to ignore it - the graph is probably loaded just fine.