rgraph6
Convert from any graph formatto rgraph6 Convert from rgraph6to any other format
rgraph6 is an R package for encoding and decoding graphs as compact strings of printable ASCII characters using Brendan McKay's format:graph6, format:sparse6, and format:digraph6 formats. It is authored and maintained by Michal Bojanowski (Kozminski University) with David Schoch, is distributed on CRAN under GPL (>= 3), and reached version 2.0-5 in April 2025. The performance-sensitive encoding and decoding routines are implemented in C++ via Rcpp, so the package depends only on Rcpp and methods; the igraph and network packages are optional (Suggests) and are used only when converting to or from those object types.
The three underlying formats all serialize an undirected or directed simple graph into a short ASCII string carrying the vertex count and the edge structure. format:graph6 packs the upper triangle of the adjacency matrix bit by bit and is most compact for dense graphs; format:sparse6 uses an incremental edge encoding that is far smaller for sparse graphs and can represent loops; and format:digraph6 stores the full adjacency matrix for directed graphs. Because each graph becomes a single self-delimiting string, many graphs can be stored one-per-line in a text file or as a column in a data frame.
The package exposes a symmetric API. Encoders as_graph6(), as_sparse6(), and as_digraph6() accept adjacency matrices, edge lists, tool:igraph graphs, or network objects and return character vectors. Decoders reverse the process at the chosen level of abstraction: adjacency_from_text(), edgelist_from_text(), igraph_from_text(), and network_from_text() detect the format from each string's prefix and reconstruct the requested representation. This makes rgraph6 a natural bridge between the graph6 ecosystem and R's two dominant network-analysis stacks.
Its main value is in tidy, large-scale graph workflows: storing thousands of small graphs compactly alongside computed metrics in CSV files, interoperating with nauty/geng-style graph generators and repositories that already emit graph6, and combining with dplyr pipelines to compute per-graph statistics. Related tooling includes the C/nauty family (tool:nauty) that originated these formats and the Perl tool:perl-graph-graph6 implementation. Limitations follow from the formats themselves: they capture only vertex count and adjacency, so vertex and edge attributes, weights, and identifiers are discarded, and sparse6 versus graph6 must be chosen with density in mind to realize the space savings.
Graph Formats(Input & Output)
Frequently Asked Questions
What graph file formats does rgraph6 support?
See the list on this page — it shows every format rgraph6 can read, write and display.
How do I import a graph into rgraph6?
Convert your file to a format rgraph6 can read, then open it in rgraph6. Use GraphInOut to get a rgraph6-compatible file in seconds.
How do I convert a file so rgraph6 can open it?
Use the convert links above — upload or paste your graph, pick a format rgraph6 accepts and download the result, right in your browser.