The Hobbit, or There and Back Again, by Alan Lee

The Hobbit, or There and Back Again, by Alan Lee

In an effort to achieve this (last paragraph), I created a couple of functions to coerce networks as ‘igraph’ objects to networks as ‘network’ objects and vice versa. I wrapped them into a package called ‘intergraph’ which I just uploaded to my personal miniCRAN.

Do mind, this is still an experimental version! Might be bug-infested.

The package depends on ‘igraph’ and ‘network’ packages (big thanks to Gabor Csardi and Tamas Nepusz for ‘igraph’ and to Carter Butts and the Statnet team for ‘network’!). At the time of writing this the ‘network’ package available on CRAN (version 1.4-1) does not have a namespace. To be able to work with both ‘igraph’ and ‘network’ together reliably I had to create a version of the ‘network’ package with the namespace. To try ‘intergraph’ you will need to install the namespaced version. Installation instructions are at the bottom.

The package contain two major functions asIgraph() and a asNetwork() method for ‘igraph’ objects. Consequently, you can go back and forth between the two representations as in:

## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
##     decompose, spectrum
## The following object is masked from 'package:base':
##     union
ig <- graph.full(10)
netg <- asNetwork(ig)
ig2 <- asIgraph(netg)

Because ‘network’ objects define some additional attributes (like na etc.) which are not used by ‘igraph’ objects ig and ig2 will not be exectly identical (in the sense of identical()) . The only potential differences though is due to these attributes.

Fooling around further:

## network: Classes for Relational Data
## Version 1.16.0 created on 2019-11-30.
## copyright (c) 2005, Carter T. Butts, University of California-Irvine
##                     Mark S. Handcock, University of California -- Los Angeles
##                     David R. Hunter, Penn State University
##                     Martina Morris, University of Washington
##                     Skye Bender-deMoll, University of Washington
##  For citation information, type citation("network").
##  Type help("network-package") to get started.
## Attaching package: 'network'
## The following objects are masked from 'package:igraph':
##     %c%, %s%, add.edges, add.vertices, delete.edges, delete.vertices,
##     get.edge.attribute, get.edges, get.vertex.attribute, is.bipartite,
##     is.directed, list.edge.attributes, list.vertex.attributes,
##     set.edge.attribute, set.vertex.attribute
net1 <- asNetwork(exIgraph)
ig1 <- asIgraph(net1)
net2 <- asNetwork(ig1)
k <- layout.fruchterman.reingold(ig1)
layout(matrix(1:4, 2, 2, byrow=TRUE))
  main="Original 'igraph'"
  main="'igraph' > 'network'", 
  label=net1 %v% "label"
  main="'igraph' > 'network' > 'igraph'"
  main="'igraph' > 'network' > 'igraph' > 'network'", 
  label=net2 %v% "label", 

I’m going to test this a bit still, and you are welcome to do that too.Bug reports, comments etc. are more than welcome.  If everything is OK the package will be available through CRAN.

Installation instructions

Namespaced ‘network’ package

To install namespaced version of the ‘network’ package (tagged with version 1.4-1-1) call:

install.packages("network", contriburl="")

To install a Windows binary version use one of

install.packages("network", contriburl="")
install.packages("network", contriburl="")
install.packages("network", contriburl="")

depending on your R version. Sorry, no other R Windows versions supported at this time. I don’t have the facilities to build Mac binaries either.

If you don’t want to overwrite the version of the ‘network’ package you already have installed you can install it to a different directory (essentially separate R library tree) following these steps:

  1. Create a new directory somewhere, like ~/lib/R/dev or c:\R\library2 etc.
  2. Run one of the above commands with an additional argument ‘lib’ set to the path to that new directory. The package will be installed there.
  3. Now when you launch R to load the new package you have to either:
    1. Use library(network, lib="pathToWherePackageIsInstalled")
    2. Or let R know about the new library tree by calling .libPaths("pathToWherePackageIsInstalled") then load the package with library(network).

I do hope the next version of ‘network’ will have a namespace.

The ‘intergraph’ package

To install the ‘intergraph’ package itself use

install.packages("intergraph", repos="")