Skip to content

Commit

Permalink
Ensure missing edge attributes are filled with NA instead of NULL
Browse files Browse the repository at this point in the history
'plyr::rbind.fill' uses NULL to fill missing values in lists. As we now
use lists for most edge attributes, we need to handle this case
separately to ensure missing values are filled with NAs instead.

To fix this issue, we need to instantiate missing columns in dataframes
with NAs before calling 'plyr::rbind.fill'. This operation is constant
with respect to the amount of rows and should not impact performance too
much.

This works towards fixing se-sic#271.

Signed-off-by: Maximilian Löffler <[email protected]>
  • Loading branch information
maxloeffler committed Dec 7, 2024
1 parent e234fc2 commit 880e70e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions util-networks.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 880e70e

Please sign in to comment.