Skip to content

tbl_vars() accesses nrow() unnecessarily #7668

@krlmlr

Description

@krlmlr

This currently affects joins with library(duckplyr) . I can work around, perhaps we find a nicer way.

Difficult to show with current duckplyr because we have our group_vars() method. The calling sequence goes as follows:

  • tbl_vars() calls group_vars() in the generic
  • group_vars.data.frame() calls names(group_data())
  • group_data() needs nrow()

Perhaps we can implement an ALTREP solution for group_vars() ? Or add an argument to group_data() that indicates we really only care about the names?

Relevant backtrace from a debugging session:

Backtrace:
     ▆
  1. ├─testthat::expect_error(...) at test-tpch.R:245:3
  2. │ └─testthat:::expect_condition_matching(...)
  3. │   └─testthat:::quasi_capture(...)
  4. │     ├─testthat (local) .capture(...)
  5. │     │ └─base::withCallingHandlers(...)
  6. │     └─rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
  7. └─duckplyr:::tpch_02() at test-tpch.R:247:5
  8.   ├─dplyr::inner_join(na_matches = TPCH_NA_MATCHES, p, ps, by = c(p_partkey = "ps_partkey")) at duckplyr/R/tpch.R:35:3
  9.   └─duckplyr (local) inner_join.data.frame(na_matches = TPCH_NA_MATCHES, p, ps, by = c(p_partkey = "ps_partkey"))
 10.     ├─duckplyr:::rel_try(...) at duckplyr/R/inner_join.R:10:3
 11.     │ └─base::force(rel) at duckplyr/R/relational.R:62:5
 12.     └─duckplyr:::rel_join_impl(...) at duckplyr/R/inner_join.R:22:7
 13.       └─duckplyr:::tbl_vars_safe(x) at duckplyr/R/join.R:19:3
 14.         └─dplyr::tbl_vars(x) at duckplyr/R/join.R:142:3
 15.           ├─dplyr:::new_sel_vars(tbl_vars_dispatch(x), group_vars(x))
 16.           │ └─base::structure(...)
 17.           ├─dplyr::group_vars(x)
 18.           └─dplyr:::group_vars.data.frame(x)
 19.             ├─generics::setdiff(names(group_data(x)), ".rows")
 20.             ├─dplyr::group_data(x)
 21.             └─dplyr:::group_data.data.frame(x)
 22.               └─base::nrow(.data)
 23.                 ├─base::dim(x)
 24.                 └─base::dim.data.frame(x)
 25.                   └─base::.row_names_info(x, 2L)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions