Researchers regularly need to work with a variety of external data formats. The following functions offer ways to import from some common external file formats into objects that {migraph} and other graph/network packages in R can work with.

Note that these functions are not as actively maintained as others in the package, so please let us know if any are not currently working for you or if there are missing import routines by raising an issue on Github.

read_matrix(file = file.choose(), sv = c("comma", "semi-colon"), ...)

read_edgelist(file = file.choose(), sv = c("comma", "semi-colon"), ...)

write_edgelist(object, filename, name, ...)

read_nodelist(file = file.choose(), sv = c("comma", "semi-colon"), ...)

write_nodelist(object, filename, name, ...)

read_pajek(file = file.choose(), ties = NULL, ...)

write_pajek(object, filename, ...)

read_ucinet(file = file.choose())

write_ucinet(object, filename, name)

read_dynetml(file = file.choose())


read_ucinet() and write_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) or "semi-colon" (European) separated.


Additional parameters passed to the read/write function.


An object of a migraph-consistent class:

  • matrix (adjacency or incidence) from {base} R

  • edgelist, a data frame from {base} R or tibble from {tibble}

  • igraph, from the {igraph} package

  • network, from the {network} package

  • tbl_graph, from the {tidygraph} package


UCINET filename (without ## extension). By default the files will have the same name as the object and be saved to the working directory.


name of matrix to be known in UCINET. By default the name will be the same as the object.


Where there are


read_edgelist() and read_nodelist() will import into edgelist (tibble) format which can then be coerced or combined into different graph objects from there.

read_pajek() and read_ucinet() will import into a tidygraph format, since they already contain both edge and attribute data. read_matrix() will import into tidygraph format too. Note that all graphs can be easily coerced into other formats with {migraph}'s as_ methods.

The write_functions export to different file formats, depending on the function.

A pair of UCINET files in V6404 file format (.##h, .##d)


There are a number of repositories for network data that hold various datasets in different formats. See for example:

See also:

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_matrix(): Reading adjacency matrices from Excel/csv files

  • read_edgelist(): Reading edgelists from Excel/csv files

  • write_edgelist(): Writing edgelists to csv files

  • read_nodelist(): Reading nodelists from Excel/csv files

  • write_nodelist(): Writing nodelists to csv files

  • read_pajek(): Reading pajek (.net/.paj) files

  • write_pajek(): Writing pajek .net files

  • read_ucinet(): Reading UCINET files

  • write_ucinet(): Writing UCINET files

  • read_dynetml(): Reading DynetML files

See also


Other makes: create, generate


if (FALSE) {
# import Roethlisberger & Dickson's horseplay game data set:
horseplay <- read_ucinet("WIRING-RDGAM.##h")
if (FALSE) {
# export it again to UCINET under a different name:
write_ucinet(horseplay, "R&D-horseplay")