Export Graph in R via JSON

This post presents an easy solution for exporting and importing a graph object of igraph library.
In its previous versions, the library used to have the save and load functions in which you could respectively export and import the graph object [1]. Although they seem to not be in the library anymore, the documentation states:

“Attribute values can be set to any R object, but note that storing the graph in some file formats might result the loss of complex attribute values. All attribute values are preserved if you use save and load to store/retrieve your graphs.

The library also proposes write_graph and read_graph, that rely on the GraphML format, for exporting and importing back graph objects.

However, here I propose my little solution with almost zero options. It saves the graph and allows to re-load it again (in another session as well) simply saving all the fields and values in a JSON file.

Read more