rstudio / ggvis

Interactive grammar of graphics for R
Other
713 stars 171 forks source link

no applicable method for 'group_by_' applied to an object of class "ggvis" #474

Open maspotts opened 7 years ago

maspotts commented 7 years ago

I have run into an unexpected problem when including a call to ggvis::group_by in a library I'm building. This is the offending code:

 x %>% gather(key, value, -x) %>% bind_rows(s) %>% ggvis(~x, ~value) %>%
          layer_points(fill=~key) %>% group_by(key) %>% layer_paths(stroke=~key)

and it works great if I paste it directly into my R shell. But when I build it into a library, using:

 #' @importFrom ggvis ggvis layer_points layer_paths group_by

and then try to execute that code I get this error:

Error in UseMethod("groupby") : no applicable method for 'groupby' applied to an object of class "ggvis"

I see that ggvis::group_by is just UseMethod("group_by") in the dplyr namespace. I've tried importing group_by (and even also groupby) from dplyr, but nothing helped. I'm at a loss to understand what I'm doing wrong, or conceivably I've found a bug? I did find references to this error message being due to a long-fixed bug in ggvis (https://github.com/rstudio/ggvis/commit/6c1ebbe13e4573458637d655dd46b8d8cf544abf), which appears to add groupby as an export in ggvis' namespace.

I've replicated this problem under the latest ggvis (0.4.3) and both dplyr 0.5.0 and 0.7.0.

Any help will be gratefully appreciated!

hadley commented 7 years ago

I suspect the problem is that ggvis isn't exporting the group_by_ method.

maspotts commented 7 years ago

Thanks! Is that something I can work around? I’m pretty much stuck otherwise!

Commit (https://github.com/rstudio/ggvis/commit/6c1ebbe13e4573458637d655dd46b8d8cf544abf) added export of groupby.ggvis. Is that relevant? I’m surprised that I’d be the first person to try to put a group_by() call into a library though!

Mike

On Jun 22, 2017, at 7:11 AM, Hadley Wickham notifications@github.com wrote:

I suspect the problem is that ggvis isn't exporting the groupby method.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rstudio/ggvis/issues/474#issuecomment-310392010, or mute the thread https://github.com/notifications/unsubscribe-auth/AD6BvtYYU3h1QPknfmYQfDFHzaKZNE-Fks5sGnYWgaJpZM4OBcNk.

maspotts commented 7 years ago

I had a poke around in the ggvis source code, and I can't find a groupby function. It defines groupby.ggvis and groupby.reactive (both wrap around dplyr::groupby ) and exports them both, but no groupby . I managed to get rid of the error by replacing group_by(key) with groupby.ggvis("key"). Still don't understand why that's only necessary when calling it from my own package though!