write.graph {igraph} | R Documentation

## Writing the graph to a file in some format

### Description

`write.graph` is a general function for exporting graphs to foreign file formats, however not many formats are implemented right now.

### Usage

    write.graph(graph, file, format=c("edgelist", "pajek", "ncol",
           "lgl", "graphml", "dimacs", "gml", "dot"), ...)

### Arguments

`graph` | The graph to export.
`file` | A connection or a string giving the file name to write the graph to.
`format` | Character string giving the file format. Right now `pajek`, `graphml`, `dot`, `gml`, `edgelist`, `lgl`, `ncol` and `dimacs` are implemented. As of igraph 0.4 this argument is case insensitive.
`...` | Other, format specific arguments, see below.

### Details

The `edgelist` format is a simple text file, with one edge in a line, the two vertex ids separated by a space character. The file is sorted by the first and the second column. This format has no additional arguments.

The Pajek format is a text file, see `read.graph` for details. Appropriate vertex and edge attributes are also written to the file. This format has no additional arguments.

The GraphML format is a flexible XML based format. See `read.graph` for GraphML details. Vertex and edge attributes are also written to the file. This format has no additional arguments.

The dot format is used by the popular GraphViz program. Vertex and edge attributes are written to the file. There are no additional arguments for this format.

The `lgl` format is also a simple text file, this is the format expected by the 'Large Graph Layout' layout generator software. See read.graph for details. Additional arguments:

names
  If you want to write symbolic vertex names instead of vertex ids, supply the name of the vertex attribute containing the symbolic names here. By default the ‘name’ attribute is used if there is one. Supply `NULL` if you want to use numeric vertex ids even if there is a ‘name’ vertex attribute.
weights
  If you want to write edge weights to the file, supply the name of the edge attribute here. By defaults the vertex attribute ‘weights’ are used if they are installed. Supply `NULL` here if you want to omit the weights.
isolates
  Logical, if `TRUE` the isolate vertices are also written to the file, they are omitted by default.

The `ncol` format is also used by LGL, it is a text file, see read.graph for details. Additional arguments:

names
  If you want to write symbolic vertex names instead of vertex ids, supply the name of the vertex attribute containing the symbolic names here. By default the ‘name’ attribute is used if there is one. Supply `NULL` if you want to use numeric vertex ids even if there is a ‘name’ vertex attribute.
weights
  If you want to write edge weights to the file, supply the name of the edge attribute here. By defaults the vertex attribute ‘weights’ are used if they are installed. Supply `NULL` here if you want to omit the weights.

The `dimacs` file format, more specifically the version for network flow problems, see the files at ftp://dimacs.rutgers.edu/pub/netflow/general-info/

This is a line-oriented text file (ASCII) format. The first character of each line defines the type of the line. If the first character is `c` the line is a comment line and it is ignored. There is one problem line (`p` in the file, it must appear before any node and arc descriptor lines. The problem line has three fields separated by spaces: the problem type (`min`, `max` or `asn`), the number of vertices and number of edges in the graph. Exactly two node identification lines are expected (`n`), one for the source, one for the target vertex. These have two fields: the id of the vertex and the type of the vertex, either `s` (=source) or `t` (=target). Arc lines start with `a` and have three fields: the source vertex, the target vertex and the edge capacity.

Vertex ids are numbered from 1.

Additional arguments:

source
  The id of the source vertex, if `NULL` (the default) then it is taken from the `source` graph attribute.
target
  The id of the target vertex, if `NULL` (the default) then it is taken from the `target` graph attribute.
capacity
  A numeric vector giving the edge capacities. If `NULL` (the default) then it is taken from the `capacity` edge attribute.

GML is a quite general textual format, see http://www.infosun.fim.uni-passau.de/Graphlet/GML/ for details.

The graph, vertex and edges attributes are written to the file as well, if they are numeric of string.

As igraph is more forgiving about attribute names, it might be neccessary to simplify the them before writing to the GML file. This way we'll have a syntactically correct GML file. The following simple procedure is performed on each attribute name: first the alphanumeric characters are extracted, the others are ignored. Then if the first character is not a letter then the attribute name is prefixed with <quote>igraph</quote>. Note that this might result identical names for two attributes, igraph does not check this.

The “id” vertex attribute is treated specially. If the `id` argument is not `NULL` then it should be a numeric vector with the vertex ids and the “id” vertex attribute is ignored (if there is one). If `id` is 0 and there is a numeric `id` vertex attribute that is used instead. If ids are not specified in either way then the regular igraph vertex ids are used.

Note that whichever way vertex ids are specified, their uniqueness is not checked.

If the graph has edge attributes named “source” or “target” they're silently ignored. GML uses these attributes to specify the edges, so we cannot write them to the file. Rename them before calling this function if you want to preserve them.

Additional arguments:

id
  `NULL` or a numeric vector giving the vertex ids. See details above.
creator
  A character scalar to be added to the “Creator” line in the GML file. If this is `NULL` (the default) then the current date and time is added.

### Value

A NULL, invisibly.

### Author(s)

Gabor Csardi csardi@rmki.kfki.hu

### References

Adai AT, Date SV, Wieland S, Marcotte EM. LGL: creating a map of protein function with an algorithm for visualizing very large biological networks. J Mol Biol. 2004 Jun 25;340(1):179-90.

### See Also

`read.graph`

### Examples

    g <- graph.ring(10)
    ## Not run: write.graph(g, "/tmp/g.txt", "edgelist")

[Package igraph version 0.5.2 Index]