Skip to content

Commit

Permalink
Fix the class of the date attribute on multi networks (due to a bug i…
Browse files Browse the repository at this point in the history
…n igraph)

As of igraph version 1.4.0, igraph respects the classes of edge and vertex
attributes. However, the function `igraph::disjoint_union` does not respect
their classes and converts `POSIXct` attributes to numeric attributes, for
instance. This is a bug in igraph that is expected to be fixed in later igraph
versions. For now, we temporarily fix this problem on our own by converting the
`date` attribute of the union back to `POSIXct`.
Note: Also other attributes could be affected! However, for convenience reasons,
we only apply our temporary fix to the `date` attribute.

This addresses #236.

Signed-off-by: Thomas Bock <bockthom@cs.uni-saarland.de>
  • Loading branch information
bockthom committed Apr 2, 2023
1 parent b8232c0 commit a953555
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions util-networks.R
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,23 @@ NetworkBuilder = R6::R6Class("NetworkBuilder",
## combine the networks:
## 1) merge the existing networks
u = igraph::disjoint_union(authors.net, artifacts.net)

## As there is a bug in 'igraph::disjoint_union' in igraph versions 1.4.0 and 1.4.1
## (see https://github.com/igraph/rigraph/issues/761), we need to adjust the type of the date attribute
## of the outcome of 'igraph::disjoint_union'.
## Note: The following temporary fix only considers the 'date' attribute. However, this problem could also
## affect several other attributes, whose classes are not adjusted in our temporary fix.
## The following code block should be redundant as soon as igraph has fixed their bug.
u.actual.edge.attribute.date = igraph::get.edge.attribute(u, "date")
if (!is.null(u.actual.edge.attribute.date)) {
if (is.list(u.actual.edge.attribute.date)) {
u.expected.edge.attribute.date = lapply(u.actual.edge.attribute.date, get.date.from.unix.timestamp)
} else {
u.expected.edge.attribute.date = get.date.from.unix.timestamp(u.actual.edge.attribute.date)
}
u = igraph::set.edge.attribute(u, "date", value = u.expected.edge.attribute.date)
}

## 2) add the bipartite edges
u = add.edges.for.bipartite.relation(u, authors.to.artifacts, private$network.conf)

Expand Down

0 comments on commit a953555

Please sign in to comment.