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

egor and dplyr #13

Closed mbojan closed 4 years ago

mbojan commented 7 years ago

Currently egor objects extend tbl_df which promises being able to take advantage of all the "dplyr" functionality cheaply. However, I just noticed that some of the "dplyr" functions drop the attributes. Try

library(dplyr)
egor32 %>%
+   mutate(woman = sex == "w") %>%
+   class()
## [1] "tbl_df"     "tbl"        "data.frame"

So not an egor anymore and all the attributes are lost :(

It seems to me that keeping "dplyr" compatibility would probably require implementing methods for all the "dyplr" verbs, e.g. mutate.egor and so on. This is unfortunate because I suspect that moving away from old "egonetR" implementation to "egor" was also to have the connection to "tidyverse" for a low development price.

mbojan commented 7 years ago

See also "13.5.3 Methods" at http://adv-r.hadley.nz/s3.html#inheritance If we follow that path, I think we are in for quite some additional effort.

mbojan commented 7 years ago

This issue is also related to #10

krivit commented 7 years ago

Not much we can do about it but hunker down and make it work, I think.

krivit commented 7 years ago

@tilltnet, thanks for implementing; three questions:

  1. How does 5d53686 handle design attributes? The dplyr verbs that subset or duplicate rows need to pass the update on to the ego.design. For example [.egor does that at https://github.com/tilltnet/egor/blob/2f0389e9a72ddf1b6348bed264dfadc55ecf3796/R/subset.egor.R#L194 .
  2. Does it protect the special columns like .alts and .aaties?
  3. Do we want to have a similar mechanism as in [.egor and subset.egor, where we can manipulate the egos, the alters, or the alter-alter ties?
tilltnet commented 7 years ago

@krivit

  1. with acc9487 the svydesign object is now modified. For filter.egor the svydesign object is subsetted. I couldn't figure out how to get this to work when several conditional expressions are supplied separated by commas.
res <- filter(egor32, sex == "w", age == "18 - 25") # This will currently not subset the svydesign object correctly...
res <- filter(egor32, sex == "w" & age == "18 - 25") # ...while this will.

I guess there is some tidyeval function for that in the rlang package!? Any ideas?

For the other dplyr verbs the $variables object of the ego.design is updated. These changes seem to work so far.

  1. Not yet, but I will incorporate this in one of my next commits.
  2. This would be great, but I will be concentrating on other things (conversions of egor object to network/igraph and dataframes) first. Would you be willing to take care of this?

In acc9487 I also deleted the summarise method, since it is not helpful to have an egor object as a result here.

krivit commented 7 years ago

@tilltnet , 3. can wait. 1. is a problem; a somewhat clunky solution is to add row indexes, filter the frame, get the remaining row indexes, and then use those to subset the survey.design object.

tilltnet commented 7 years ago

Dang it! I referenced this issue in the wrong commit. Correct commit is: fcac6cacc7bbd2eff2e2c271e31ebe4bdf3788de

filter.egor now subsets the svydesign object correctly. It's done by adding a temporary index, as described by @krivit (Thanks!)

Still to do:

tilltnet commented 6 years ago

Maybe we could introduce an activate() function to allow for tidygraph-like operations, that would allow filtering/modifying the different data levels.

activate(egor, unit = c("ego", "alter", "aatie"))

Caveats:

mbojan commented 6 years ago

I like that direction @tilltnet , and actually mentioned that to @krivit off GitHub.