This loads a graph from a file. Currently, only GraphML files are supported.

load_graph(file, directed, filetype = "graphml")

Arguments

file

The filename to load the graph from

directed

Choose to load a directed or undirected graph. Note that this has to correspond to the type of graph described in the file!

filetype

Choose the filetype of the file. Currently, only GraphML is supported

Value

The loaded nctx graph

Details

See https://en.wikipedia.org/wiki/GraphML for further information about the file format.

Information associated to nodes are loaded as well and accessible via attribute functions, e.g. get_vertex_attributes and get_vertex_attribute_names.

See also

Examples

library(RUnit) library(nctx) file_dir <- system.file("extdata", "bcde.directed.graphml", package="nctx") file_undir <- system.file("extdata", "bcde.undirected.graphml", package="nctx") g <- load_graph(file_dir, directed=TRUE) checkEquals(num_vertices(g), 10)
#> [1] TRUE
#> [1] TRUE
#> Error in is_directed(g): Not a graph object
g <- load_graph(file_dir, TRUE) checkEquals(num_vertices(g), 10)
#> [1] TRUE
#> [1] TRUE
#> Error in is_directed(g): Not a graph object
g <- load_graph(file_undir, directed=FALSE) checkEquals(num_vertices(g), 10)
#> [1] TRUE
#> [1] TRUE
#> Error in is_directed(g): Not a graph object
g <- load_graph(file_undir, FALSE) checkEquals(num_vertices(g), 10)
#> [1] TRUE
#> [1] TRUE
#> Error in is_directed(g): Not a graph object
checkException(load_graph(file_dir, directed=FALSE))
#> Error in g$graph$from_file_graphml(file) : #> read_graphviz: Tried to read a directed graph into an undirected graph.
#> [1] TRUE
checkException(load_graph(file_undir, directed=TRUE))
#> Error in g$graph$from_file_graphml(file) : #> read_graphviz: Tried to read an undirected graph into a directed graph.
#> [1] TRUE
checkException(load_graph(file_undir, directed=FALSE, filetype="edgelist"))
#> Error in load_graph(file_undir, directed = FALSE, filetype = "edgelist") : #> fileformats other than graphml currently not supported
#> [1] TRUE