Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tbl_vars() accesses nrow() unnecessarily #7668

Open
krlmlr opened this issue Mar 9, 2025 · 0 comments
Open

tbl_vars() accesses nrow() unnecessarily #7668

krlmlr opened this issue Mar 9, 2025 · 0 comments

Comments

@krlmlr
Copy link
Member

krlmlr commented Mar 9, 2025

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant