Skip to content

filter() fails on grouped data #193

@hughjonesd

Description

@hughjonesd

Here's a reprex:

library(ggraph)
data(whigs)

whigs <- tidygraph::as_tbl_graph(whigs) |> 
  activate(nodes) |> 
  mutate(AM = grepl("^[A-M]", name)) 

# Works fine:
whigs |> filter(grepl("Austin", name))
# A tbl_graph: 2 nodes and 0 edges
#
# A rooted forest with 2 trees
#
# Node Data: 2 × 3 (active)
# ... etcetera

whigs |> group_by(AM) |> filter(grepl("Austin", name))
# A tbl_graph: 2 nodes and 0 edges
#
# A rooted forest with 2 trees
Error in `vec_slice()`:
! Column `type` (size 2) must match the data frame (size 261).In file slice.c at line 191.Install the winch package to get additional debugging info the next time you get this error.This is an internal error that was detected in the vctrs package.
  Please report it at <https://github.com/r-lib/vctrs/issues> with a reprex and the full backtrace.
Backtrace:1. ├─base (local) `<fn>`(x)
  2. ├─tidygraph:::print.tbl_graph(x)
  3. │ ├─base::print(new_name_tibble(x, NULL, top, " (active)"), ...)
  4. │ └─pillar:::print.tbl(...)
  5. │   └─pillar:::print_tbl(...)
  6. │     ├─base::writeLines(...)
  7. │     ├─base::format(...)
  8. │     └─pillar:::format.tbl(...)
  9. │       └─pillar:::format_tbl(...)
 10. │         └─pillar::tbl_format_setup(...)
 11. │           ├─pillar:::tbl_format_setup_dispatch(...)
 12. │           └─pillar:::tbl_format_setup.tbl(...)
 13. │             └─pillar:::df_head(x, n)
 14. │               └─pillar:::vec_head(as.data.frame(x), n)
 15. │                 └─vctrs::vec_slice(x, seq_len(n))
 16. └─rlang:::stop_internal_c_lib(...)
 17.   └─rlang::abort(message, call = call, .internal = TRUE, .frame = frame)

This is with tidygraph 1.3.1, R 4.4.0 and dplyr 1.1.4. Also confirmed on github as of today.

I'd expect filter to work as normal on grouped data, but I may be missing something....

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions