Skip to content

Commit

Permalink
!TEMPORARY! replace NULLs in edge attributes with NA
Browse files Browse the repository at this point in the history
This is necessary since igraph falsely fills in non-present edge
attributes with NULLs instead of NAs in certain cases when using
'igraph::disjoint_union' and 'igraph::add_edges'.
  • Loading branch information
maxloeffler committed Dec 7, 2024
1 parent 32a32f5 commit e234fc2
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 @@ -1282,6 +1282,14 @@ NetworkBuilder = R6::R6Class("NetworkBuilder",
## combine the networks:
## 1) merge the existing networks
u = igraph::disjoint_union(authors.net, artifacts.net)
for (attr in igraph::edge_attr_names(u)) {
values = igraph::edge_attr(u, attr)
NULLs = sapply(values, is.null)
if (any(NULLs)) {
values[NULLs] = NA
u = igraph::set_edge_attr(u, attr, value = values)
}
}

## As there is a bug in 'igraph::disjoint_union' in igraph from its version 1.4.0 on, which is still
## present, at least, until its version 2.0.3 (see https://github.com/igraph/rigraph/issues/761), we need
Expand Down Expand Up @@ -1806,6 +1814,15 @@ add.edges.for.bipartite.relation = function(net, bipartite.relations, network.co

## add the vertex sequences as edges to the network
net = igraph::add_edges(net, unlist(vertex.sequence.for.edges), attr = extra.edge.attributes)

for (attr in igraph::edge_attr_names(net)) {
values = igraph::edge_attr(net, attr)
NULLs = sapply(values, is.null)
if (any(NULLs)) {
values[NULLs] = NA
net = igraph::set_edge_attr(net, attr, value = values)
}
}
}

return(net)
Expand Down

0 comments on commit e234fc2

Please sign in to comment.