Skip to content

add stats:: in front of stats functions that were not explicitly imported#6793

Merged
teunbrand merged 2 commits intotidyverse:mainfrom
klin333:explicit-deps
Feb 4, 2026
Merged

add stats:: in front of stats functions that were not explicitly imported#6793
teunbrand merged 2 commits intotidyverse:mainfrom
klin333:explicit-deps

Conversation

@klin333
Copy link
Copy Markdown
Contributor

@klin333 klin333 commented Jan 20, 2026

This problem of not explicitly putting stats:: in front of stats package functions was previously documented in #5186. Previously the fix was done in eg #5514

This PR is similar, cleaning up more calls to stats functions that do not have stats:: in front of them.

@klin333
Copy link
Copy Markdown
Contributor Author

klin333 commented Feb 3, 2026

hi maintainers, maybe @teunbrand? Could you help allow this merge. the check failures seems unrelated to this PR, though i'm not sure... thank you.

@Breeze-Hu
Copy link
Copy Markdown

Did the previous PR replace stats::ave with vec_ave? #6698
Is this missing? Rather than using stats::ave?

@teunbrand
Copy link
Copy Markdown
Collaborator

@Breeze-Hu is right. Instead of prefixing the ave() function, can you replace it with vec_ave() instead?

@klin333
Copy link
Copy Markdown
Contributor Author

klin333 commented Feb 3, 2026

thanks guys, but i don't think it's a simple replace for those remaining stats::ave to vec_ave

These remaining stats::ave has multiple grouping variables, but the vec_ave only supports 1 grouping variable

ggplot2/R/position-dodge.R

Lines 152 to 154 in 1052371

data$order <- xtfrm( # xtfrm makes anything 'sortable'
data$order %||% ave(data$group, data$x, data$PANEL, FUN = match_sorted)
)

ggplot2/R/utilities.R

Lines 938 to 947 in 1052371

vec_ave <- function(x, by, fn, ...) {
idx <- vec_group_loc(by)$loc
list_unchop(
lapply(
vec_chop(x, indices = idx),
FUN = fn, ...
),
indices = idx
)
}

I think this PR is unrelated the to stats::ave -> vec_ave change from #6698. Any way we can allow this PR through without being blocked by these unrelated changes? Ideally there should be a continuation of #6698 separately, assuming that PR simply missed these stats::ave, again probably because these weren't prefixed with stats::.

This forgetting of prefixing stats:: just keeps creeping up year after year, to the point where perhaps it's better to just import all of stats, or configure testthat to run all test suite without stats imported at R startup. But that's above my pay grade, probably @teunbrand

## usethis namespace: start
#' @import scales grid gtable rlang vctrs
#' @importFrom lifecycle deprecated
#' @importFrom stats setNames
#' @importFrom utils head tail
## usethis namespace: end
NULL

@teunbrand
Copy link
Copy Markdown
Collaborator

I've added the vec_ave() myself.

This forgetting of prefixing stats:: just keeps creeping up year after year

Yeah it just part of the general fight against entropy. I'd not be happy to wholesale import stats, but it might be fine if somebody wants to contribute a separate PR that creates a unit test to guard against this.

Copy link
Copy Markdown
Collaborator

@teunbrand teunbrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution!

@teunbrand teunbrand merged commit 2b5dffd into tidyverse:main Feb 4, 2026
26 of 31 checks passed
teunbrand pushed a commit that referenced this pull request Apr 13, 2026
…rted (#6793)

* add stats:: in front of stats functions that were not explicitly imported

* use `vec_ave()`
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.

3 participants