Skip to content

Fix error index in summarise() and reframe() when across() expands - #7857

Open
taekop wants to merge 1 commit into
tidyverse:mainfrom
taekop:fix-error-index-across
Open

taekop wants to merge 1 commit into
tidyverse:mainfrom
taekop:fix-error-index-across

Conversation

@taekop

@taekop taekop commented Oct 5, 2026

Copy link
Copy Markdown

When a size error happens in summarise() or reframe() after an across() (or an unnamed data frame result) has been expanded, the error handler indexes dots with a position that counts the expanded columns instead of the original expressions:

tibble(x = 1:3, y = 4:6) |>
  reframe(across(everything(), \(x) rep(letters[x], each = x)))
#> Error in `names(dots)[[i]]`:
#> ! subscript out of bounds

The C side reports index_expression as a position in chunks, which has one entry per expanded column. summarise_cols() now records which expression each chunk came from and maps the index back before building the error context. With this the call above gives the usual recycling error (across(...) must be size 3 or 1, not 12), and the same goes for a bad expression that comes after an across(), e.g. summarise(df, across(everything(), mean), z = 1:2) now names z.

I ran a set of summarise/reframe calls (across, data frame results, NULL results, grouped, errors and successes) before and after. Results are identical; the error messages that changed are the ones that used to hit the subscript error, plus one that used to blame the wrong expression: after an across() that selects no columns, summarise(df, across(c(), mean), z = 1:2) used to name across(c(), mean) and now names z. There's no measurable slowdown on a 2000 column across().

The new tests are snapshot tests through summarise() and reframe(); they fail without the change. The full suite has the same failures on main without this change (all-equal, bind-rows, case-when, recode-values, which look like R 4.6 differences).

Closes #7657

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

reframe with across returns an unhelpful error message

1 participant