Learn R Programming

migraph (version 0.12.1)

read: Make networks from/to external formats

Description

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.

Usage

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(), ...)

write_pajek(object, filename, ...)

read_ucinet(file = file.choose())

write_ucinet(object, filename, name)

Value

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

The read_pajek() and read_ucinet() functions will import into a tidygraph format, since they already contain both edge and attribute data. 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)

Arguments

file

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.

sv

Allows users to specify whether their csv file is "comma" (English) or "semi-colon" (European) separated.

...

Additional parameters passed to the read/write function.

object

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

filename

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

name

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

Functions

  • 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

Details

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.

See Also

as

Other makes: create, generate

Examples

Run this code
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")
}

Run the code above in your browser using DataLab