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_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_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 a cognitive social structure (see is_cognitive()).
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 a cognitive social structure (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.
as
Other makes:
make_collect,
make_create,
make_ego,
make_explicit,
make_learning,
make_play,
make_random,
make_stochastic,
make_write