diff --git a/util-networks.R b/util-networks.R index 2e159fcc..a54129b4 100644 --- a/util-networks.R +++ b/util-networks.R @@ -1674,9 +1674,18 @@ merge.network.data = function(vertex.data, edge.data) { edge.data.filtered = Filter(function(ed) { return(nrow(ed) > 0) }, edge.data) - ## 2) call rbind + ## 2) add in missing columns + all.columns = Reduce(union, lapply(edge.data.filtered, colnames)) + edge.data.filtered = lapply(edge.data.filtered, function(edges) { + missing.columns = setdiff(all.columns, colnames(edges)) + for (column in missing.columns) { + edges[[column]] = NA + } + return(edges) + }) + ## 3) call rbind edges = plyr::rbind.fill(edge.data.filtered) - ## 3) correct empty results + ## 4) correct empty results if (is.null(edges)) { edges = create.empty.edge.list() } @@ -1807,7 +1816,7 @@ add.edges.for.bipartite.relation = function(net, bipartite.relations, network.co ## convert edge attributes to list similarely to 'convert.edge.attributes.to.list' edge.attrs = names(extra.edge.attributes) - which.attrs = !(edge.attrs %in% EDGE.ATTR.HANDLING) + which.attrs = !(edge.attrs %in% names(EDGE.ATTR.HANDLING)) for (attr in edge.attrs[which.attrs]) { extra.edge.attributes[[attr]] = as.list(extra.edge.attributes[[attr]]) }