Researchers regularly need to work with a variety of external data formats.
The following functions enable importing from some common external file
formats into objects that {manynet} and other graph/network packages in R
can work with:
read_matrix() imports adjacency matrices from Excel/csv files.
read_edgelist() imports edgelists from Excel/csv files.
read_nodelist() imports nodelists from Excel/csv files.
read_pajek() imports Pajek (.net or .paj) files.
read_ucinet() imports UCINET files from the header (.##h).
read_dynetml() imports DyNetML interchange format for rich social network data.
read_graphml() imports GraphML files,
including those exported by Network Canvas.
read_gml() imports GML files.
read_gdf() imports GDF files.
read_gexf() imports GEXF files, such as those exported by Gephi.
read_hif() imports Hypergraph Interchange Format (HIF) files.
read_geojson() imports the lines of a GeoJSON file,
such as roads, rivers, or routes, as a spatial network.
read_matrix(file = file.choose(), sv = c("comma", "semi-colon"), ...)
read_edgelist(file = file.choose(), sv = c("comma", "semi-colon"), ...)
read_nodelist(file = file.choose(), sv = c("comma", "semi-colon"), ...)
read_pajek(file = file.choose(), ties = NULL, ...)
read_ucinet(file = file.choose())
read_dynetml(file = file.choose())
read_graphml(file = file.choose(), ego = TRUE)
read_gml(file = file.choose())
read_gdf(file = file.choose())
read_gexf(file = file.choose())
read_geojson(file = file.choose(), junctions = TRUE, tolerance = 0)
read_hif(file = file.choose())read_ucinet() kindly supplied by Christian Steglich,
constructed on 18 June 2015.
A character string with the system path to the file to import.
If left unspecified, an OS-specific file picker is opened to help users select it.
Note that in read_ucinet() the file path should be to the header file (.##h),
if it exists and that it is currently not possible to import multiple
networks from a single UCINET file. Please convert these one by one.
Allows users to specify whether their csv file is
"comma" (English, the default) or "semi-colon" (European) separated.
Additional parameters passed to the read/write function.
A character string indicating the ties/network, where the data contains several.
Logical, whether to add ego as a node in ego-centric formats
such as Network Canvas, where ego is otherwise only recorded at the level
of the network. By default TRUE.
Where ego is added, ties from ego to each of its alters are also added,
and every tie gains a 'by' column identifying the ego that reported it,
which makes the network an egocentric network (see is_egocentric()).
Whether to keep only the junctions and ends of the lines as nodes, joining the lines that meet at a node where nothing else does. By default TRUE. Use FALSE to keep every line in the file as a tie of its own.
How far apart two ends of lines can be and still be read as the same node, in the units of the file's coordinates. By default 0, so that only ends at the very same position are one node. Surveyed or digitised lines seldom meet at the very same position, so a small tolerance, say a metre, often recovers a better connected network.
read_edgelist() and read_nodelist() import a list rather than a
network, so they return a tibble,
which can then be coerced or combined into a network from there.
Every other read_*() function returns a stocnet object (see
make_stocnet()).
This is the class that holds the most of what a file can contain,
such as the network's metadata, more than two modes, several layers,
and the times at which nodes and ties are present.
Note that a network can be coerced into any other format
with {manynet}'s as_ methods.
There are a number of repositories for network data that hold various datasets in different formats. See for example:
Please let us know if you identify any further repositories of social or political networks and we would be happy to add them here.
The _ucinet functions only work with relatively recent UCINET
file formats, e.g. type 6406 files.
To import earlier UCINET file types, you will need to update them first.
To import multiple matrices packed into a single UCINET file,
you will need to unpack them and convert them one by one.
read_graphml() reads the file itself rather than relying on igraph,
so that keys declared for="all" and files holding more than one graph
are read rather than quietly discarded.
Where several graphs are present, they are combined into a single network
and distinguished by a 'graph' node attribute.
Network Canvas exports are recognised by their namespace and read
accordingly.
Each interview session is exported as a separate graph, so the sessions are
combined into one network in which each session is a component.
Since ego is recorded at the level of the graph rather than as a node,
and ego-alter ties are left implicit,
ego is added as a node with ties to each of its alters,
and every tie records the ego that reported it in a 'by' column,
making the result an egocentric network (see is_egocentric()).
It is not a cognitive social structure, since each ego reports on alters
of its own rather than on one roster of nodes (see is_cognitive()).
Use ego = FALSE to keep just the alters and the ties between them.
Note that node types are reported in a character 'nodeset' column rather
than a logical 'type' column, because ego networks are not two-mode:
ties within a nodeset are exactly what is collected.
Note too that, since alters are particular to a session,
the sessions share no nodes, so as_matrix() on such a network returns a
large and very sparse three-dimensional array.
read_gexf() reads the node and tie attributes declared in the file,
as well as the visualisation elements Gephi adds,
so that positions are available as 'x' and 'y' node attributes,
and sizes and colours as 'size' and 'color'.
Nodes are named from their labels where the file gives them,
since node ids are required by the format and so are an export artefact.
Dynamic files are read with their 'start' and 'end' times,
which makes the result a dynamic network (see is_dynamic()).
Where a directed network contains ties declared undirected or mutual,
those ties are reciprocated, since a network is directed or not as a whole.
read_hif() reads a file in the Hypergraph Interchange Format
(Coll et al. 2025), a JSON format that hypergraph libraries such as
HyperNetX, XGI, Hypergraphx, and SimpleHypergraphs.jl share.
It returns a 'stocnet' object that holds each hyperedge as a tie among
its nodes (see the Hypergraphs section of make_stocnet()).
The weights and attributes of the nodes and of the hyperedges become
their attributes,
and those of each node's membership of a hyperedge are kept with it,
as is the side of a directed hyperedge that the node is on:
its 'tail' is read as 'from' and its 'head' as 'to'.
The metadata become the information about the network,
and a file that says it holds an abstract simplicial complex
is marked as one.
An attribute that holds more than a single value is kept as the JSON
that records it.
read_geojson() reads each line in the file as a tie between its two ends,
and each place where the ends of lines meet as a node.
The positions of the nodes are held as 'x' and 'y' node attributes,
and 'z' where the file gives elevations,
in whatever coordinate reference system the file declares,
which makes the result a spatial network (see is_spatial()).
The properties of a line become the attributes of its tie,
together with a 'length' that is measured along the line,
unless the file gives the lines a 'length' of its own:
in metres where the coordinates are longitudes and latitudes,
or those of a Mercator projection (EPSG:3395 or EPSG:3857),
and otherwise in the units of the coordinates.
The shape of the line itself is not retained.
Any points in the file describe the nodes at their positions,
so that their properties, such as names, become node attributes,
and a point that no line ends at is read as an isolate.
Lines are often divided where nothing meets them,
say where the surface or the name of a road changes,
and so by default the ties that meet at such a node are joined,
unless a point describes that node.
A joined tie records the number of 'segments' it joins,
and its 'length' is the sum of theirs.
A length is a distance and not a weight (see tie_lengths()),
so the network is weighted only where the file gives its lines a 'weight'.
Measures of shortest paths read the lengths as they are.
Its other numeric attributes are their means, weighted by their lengths,
which is not what is wanted of an attribute that is itself a total.
Where its segments differ on any other attribute,
each of their values is given, separated by semi-colons.
Lines that share the same two ends are kept as separate ties,
since they are different routes between the same places.
Coll, Martín, Cliff A. Joslyn, Nicholas W. Landry, Quintino Francesco Lotito, Audun Myers, Joshua Pickard, Brenda Praggastis, and Przemysław Szufel. 2025. "HIF: The hypergraph interchange format for higher-order networks". Network Science 13: e21. doi:10.1017/nws.2025.10018
as
Other makes:
make_collect,
make_create,
make_ego,
make_emails,
make_explicit,
make_groups,
make_growth,
make_learning,
make_play,
make_random,
make_write