Skip to content

Commit dfa2033

Browse files
committed
Use Reduce in the (before temporary) NULL replacement for performance
The igraph maintainers decided that they will not re-install consistency with their older versions (in terms of filling in non-existent values in 'igraph::disjoint_union' and 'igraph::add_edges' with NAs) yet (igraph/rigraph#1587). The previously temporary fix is therefore now semi-permanent. Signed-off-by: Maximilian Löffler <s8maloef@stud.uni-saarland.de>
1 parent 2d2a5f6 commit dfa2033

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

util-networks.R

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,16 +1282,19 @@ NetworkBuilder = R6::R6Class("NetworkBuilder",
12821282
## combine the networks:
12831283
## 1) merge the existing networks
12841284
u = igraph::disjoint_union(authors.net, artifacts.net)
1285-
for (attr in igraph::edge_attr_names(u)) {
1285+
1286+
## 2) replace NULLs in edge attributes with NAs for consistency
1287+
u = Reduce(function(u, attr) {
12861288
values = igraph::edge_attr(u, attr)
12871289
NULLs = sapply(values, is.null)
12881290
if (any(NULLs)) {
12891291
values[NULLs] = NA
12901292
u = igraph::set_edge_attr(u, attr, value = values)
12911293
}
1292-
}
1294+
return(u)
1295+
}, igraph::edge_attr_names(u), u)
12931296

1294-
## 2) add the bipartite edges
1297+
## 3) add the bipartite edges
12951298
u = add.edges.for.bipartite.relation(u, authors.to.artifacts, private$network.conf)
12961299

12971300
## add range attribute for later analysis (if available)
@@ -1810,14 +1813,16 @@ add.edges.for.bipartite.relation = function(net, bipartite.relations, network.co
18101813
## add the vertex sequences as edges to the network
18111814
net = igraph::add_edges(net, unlist(vertex.sequence.for.edges), attr = extra.edge.attributes)
18121815

1813-
for (attr in igraph::edge_attr_names(net)) {
1816+
## replace NULLs in edge attributes with NAs for consistency
1817+
net = Reduce(function(net, attr) {
18141818
values = igraph::edge_attr(net, attr)
18151819
NULLs = sapply(values, is.null)
18161820
if (any(NULLs)) {
18171821
values[NULLs] = NA
18181822
net = igraph::set_edge_attr(net, attr, value = values)
18191823
}
1820-
}
1824+
return(net)
1825+
}, igraph::edge_attr_names(net), net)
18211826
}
18221827

18231828
return(net)

0 commit comments

Comments
 (0)