tilltnet / egor

R Package for importing and analysing ego-centered-network data.
http://egor.tillt.net
GNU Affero General Public License v3.0
23 stars 4 forks source link

as_igraph() fails when egor object has alters that appear in AATIE but not in ALTER data #52

Closed raffaelevacca closed 4 years ago

raffaelevacca commented 4 years ago

There are cases in which the alter-tie edge list data frame (say atie.data) includes alter IDs that do not appear in the alter attribute data frame (say alter.data). This may not be ideal but it's the case with some data in which certain alters in the edge list have missing attributes.

When this happens, egor(alters = alter.data, egos = foo, aaties = atie.data) correctly creates the egor object. However, when we apply as_igraph() to that object, this throws an error (screenshot below). The error happens in igraph::graph.data.frame(d, vertices) (now actually called igraph::graph_from_data_frame), which does not accept an edge list (d) with alter IDs that do not appear in the alter attribute data (vertices).

screenshot

raffaelevacca commented 4 years ago

This might be fixed by adding the missing alter IDs from d into the vertices data frame (with all their attributes set to NA) before converting to igraph via graph_from_data_frame.

tilltnet commented 4 years ago

This is an issue that I worked on before without finding a satisfying solution.

The way this should be handled by egor is that an error would be raised at the time of creation of the egor object, when alter-alter ties are referencing non-existing alters. Including a check for this in egor() is pretty straightforward, but it'll break some of the import functions and vignettes. I'll look into it.

This might be fixed by adding the missing alter IDs from d into the vertices data frame (with all their attributes set to NA) before converting to igraph via graph_from_data_frame.

This solution would help when the mismatch between alter and alter-alter tie data was intended. In cases where the mismatch is unintended (/unnoticed) egor would mask existing data problems, by giving the impression that everything is working. Making the user aware of the issue only when as_igraph() is used is also not good though. I will therefore implement the behavior described above (make egor() fail on data mismatch).

raffaelevacca commented 4 years ago

If throwing an error when the user tries to create the egor object breaks existing code, another option is giving just a warning. The function could still make the egor object (with a warning) by adding the missing alters to the alter attribute data with all attributes set to NA.

tilltnet commented 4 years ago

It works now. All test complete, but I might have introduced new issues, we'll see. It is really important, that the the IDs are consistent on every level, as filtering the egor object will otherwise lead to unexpected drops of cases with inconsistent IDs. There were already some checks for ID consistency, with this one in place we should be good on this front now.